Skip to content

Commit ccb4101

Browse files
committed
Better message
1 parent ac740e1 commit ccb4101

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

python/pyspark/find_spark_home.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def is_spark_home(path):
4040
paths = ["../", os.path.dirname(os.path.realpath(__file__))]
4141

4242
# Add the path of the PySpark module if it exists
43-
is_error_raised = False
43+
import_error_raised = False
4444
if sys.version < "3":
4545
import imp
4646
try:
@@ -50,7 +50,7 @@ def is_spark_home(path):
5050
paths.append(os.path.join(module_home, "../../"))
5151
except ImportError:
5252
# Not pip installed no worries
53-
is_error_raised = True
53+
import_error_raised = True
5454
else:
5555
from importlib.util import find_spec
5656
try:
@@ -60,7 +60,7 @@ def is_spark_home(path):
6060
paths.append(os.path.join(module_home, "../../"))
6161
except ImportError:
6262
# Not pip installed no worries
63-
is_error_raised = True
63+
import_error_raised = True
6464

6565
# Normalize the paths
6666
paths = [os.path.abspath(p) for p in paths]
@@ -69,15 +69,18 @@ def is_spark_home(path):
6969
return next(path for path in paths if is_spark_home(path))
7070
except StopIteration:
7171
print("Could not find valid SPARK_HOME while searching {0}".format(paths), file=sys.stderr)
72-
if is_error_raised:
72+
if import_error_raised:
7373
print(
74-
"Did you install PySpark via a package manager such as PIP or Conda? If so, your "
75-
"Python executable does not have the PySpark installed. It is possible your "
76-
"Python executable does not point out your PIP. Please check your default "
77-
"'python' and if you set PYSPARK_PYTHON and/or PYSPARK_DRIVER_PYTHON environment "
78-
"variables, and see if you can import PySpark. If you cannot import, you can "
79-
"install by using Python executable directly, for example, 'python -m pip "
80-
"install pyspark'", file=sys.stderr)
74+
"\nDid you install PySpark via a package manager such as PIP or Conda? If so,\n"
75+
"your PySpark was not found in your Python executable. It is possible your\n"
76+
"Python executable does not properly bind with your package manager.\n"
77+
"\nPlease check your default 'python' and if you set PYSPARK_PYTHON and/or\n"
78+
"PYSPARK_DRIVER_PYTHON environment variables, and see if you can import PySpark.\n"
79+
"\nIf you cannot import, you can install by using Python executable directly,\n"
80+
"for example, 'python -m pip install pyspark'. Otherwise, you can also\n"
81+
"explicitly set your Python executable, that has PySpark installed, to\n"
82+
"PYSPARK_PYTHON or PYSPARK_DRIVER_PYTHON environment variables, for example,\n"
83+
"'PYSPARK_PYTHON=python3 pyspark'.\n", file=sys.stderr)
8184
sys.exit(-1)
8285

8386
if __name__ == "__main__":

0 commit comments

Comments
 (0)