Skip to content

Commit bb76eae

Browse files
abhishekkrrxin
authored andcommitted
[python alternative] pyspark require Python2, failing if system default is Py3 from shell.py
Python alternative for #392; managed from shell.py Author: AbhishekKr <abhikumar163@gmail.com> Closes #399 from abhishekkr/pyspark_shell and squashes the following commits: 134bdc9 [AbhishekKr] pyspark require Python2, failing if system default is Py3 from shell.py
1 parent 6ad4c54 commit bb76eae

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

python/pyspark/shell.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020
2121
This file is designed to be launched as a PYTHONSTARTUP script.
2222
"""
23+
24+
import sys
25+
if sys.version_info.major != 2:
26+
print("Error: Default Python used is Python%s" % sys.version_info.major)
27+
print("\tSet env variable PYSPARK_PYTHON to Python2 binary and re-run it.")
28+
sys.exit(1)
29+
30+
2331
import os
2432
import platform
2533
import pyspark
@@ -34,21 +42,21 @@
3442

3543
sc = SparkContext(os.environ.get("MASTER", "local[*]"), "PySparkShell", pyFiles=add_files)
3644

37-
print """Welcome to
45+
print("""Welcome to
3846
____ __
3947
/ __/__ ___ _____/ /__
4048
_\ \/ _ \/ _ `/ __/ '_/
4149
/__ / .__/\_,_/_/ /_/\_\ version 1.0.0-SNAPSHOT
4250
/_/
43-
"""
44-
print "Using Python version %s (%s, %s)" % (
51+
""")
52+
print("Using Python version %s (%s, %s)" % (
4553
platform.python_version(),
4654
platform.python_build()[0],
47-
platform.python_build()[1])
48-
print "Spark context available as sc."
55+
platform.python_build()[1]))
56+
print("Spark context available as sc.")
4957

5058
if add_files != None:
51-
print "Adding files: [%s]" % ", ".join(add_files)
59+
print("Adding files: [%s]" % ", ".join(add_files))
5260

5361
# The ./bin/pyspark script stores the old PYTHONSTARTUP value in OLD_PYTHONSTARTUP,
5462
# which allows us to execute the user's PYTHONSTARTUP file:

0 commit comments

Comments
 (0)