pyspark模块在spark正在使用的python实例中不可用

时间:2017-10-17 18:42:39

标签: python apache-spark pyspark amazon-emr

我正在使用我自己未在AWS中设置的EMR。

我正在尝试理解Python解释器使用的内容,在我的.bashrc中我有以下设置export PYSPARK_PYTHON=/mnt/anaconda/bin/python

当我运行spark-submit命令时,我使用sys.executable打印到python解释器的路径,这确实是它使用的解释器。

但是,当我专门访问该文件夹时,使用./python启动该Python实例,然后尝试import pyspark我得到:

>>> import pyspark
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named pyspark

这里发生了什么?难道这个解释器不应该安装pyspark模块吗?

1 个答案:

答案 0 :(得分:0)

当你调用spark-submit时,它会将它自己的python文件夹和py4j库添加到PYTHONPATH中。他们住在安装的spark文件夹中,它们没有直接安装到你正在使用的python的site-packages中。例如,如果我在python路径中打印出一个打印:

$ pyspark
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
17/10/17 15:34:04 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
17/10/17 15:34:04 WARN Utils: Your hostname, rwidmaier resolves to a loopback address: 127.0.0.1; using 10.4.248.126 instead (on interface em1)
17/10/17 15:34:04 WARN Utils: Set SPARK_LOCAL_IP if you need to bind to another address
/home/rwidmaier/apps/spark/python/pyspark/context.py:195: UserWarning: Support for Python 2.6 is deprecated as of Spark 2.0.0
  warnings.warn("Support for Python 2.6 is deprecated as of Spark 2.0.0")
17/10/17 15:34:09 WARN ObjectStore: Version information not found in metastore. hive.metastore.schema.verification is not enabled so recording the schema version 1.2.0
17/10/17 15:34:09 WARN ObjectStore: Failed to get database default, returning NoSuchObjectException
17/10/17 15:34:09 WARN ObjectStore: Failed to get database global_temp, returning NoSuchObjectException
Welcome to
      ____              __
     / __/__  ___ _____/ /__
    _\ \/ _ \/ _ `/ __/  '_/
   /__ / .__/\_,_/_/ /_/\_\   version 2.2.0
      /_/

Using Python version 2.6.6 (r266:84292, Aug 18 2016 15:13:37)
SparkSession available as 'spark'.
>>> import sys
>>> from pprint import pprint
>>> pprint(sys.path)
['',
 u'/tmp/spark-0a08efa7-714a-498b-b5e9-bba48684d52d/userFiles-52012e25-d7af-4599-a214-9637141ed4ec',
 '/usr/lib64/python2.6/site-packages/deluge-1.3.11-py2.6-linux-x86_64.egg',
 '/home/ryan/apps/spark/python/lib/py4j-0.10.4-src.zip',
 '/home/ryan/apps/spark/python',
 '/usr/lib64/python26.zip',
 '/usr/lib64/python2.6',
 '/usr/lib64/python2.6/plat-linux2',
 '/usr/lib64/python2.6/lib-tk',
 '/usr/lib64/python2.6/lib-old',
 '/usr/lib64/python2.6/lib-dynload',
 '/usr/lib64/python2.6/site-packages',
 '/usr/lib64/python2.6/site-packages/gst-0.10',
 '/usr/lib64/python2.6/site-packages/gtk-2.0',
 '/usr/lib64/python2.6/site-packages/webkit-1.0',
 '/usr/lib/python2.6/site-packages']

您可以在列表中看到它已手动添加:

  • /home/ryan/apps/spark/python/lib/py4j-0.10.4-src.zip
  • /家庭/莱恩/应用/火花/蟒

要确保解释器始终使用正确的库进行设置,您只需将PYSPARK_PYTHON设置为指向您要使用的python安装,然后运行“pyspark”而不是直接运行python。或者,如果您想提供驱动程序,则可以使用spark-submit。