Python 设置Pypark

Python 设置Pypark,python,apache-spark,pyspark,Python,Apache Spark,Pyspark,我已经安装了Scala和Spark,但PySpark不工作。下面是我得到的答案: user@ubuntu:~/spark$ pyspark Python 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. Traceback (most recent call last): Fi

我已经安装了Scala和Spark,但PySpark不工作。下面是我得到的答案:

user@ubuntu:~/spark$ pyspark 
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Traceback (most recent call last):
  File "/home/user/spark/python/pyspark/shell.py", line 30, in <module>
    import pyspark
  File "pyspark.py", line 1, in <module>
NameError: name 'sc' is not defined
我做错了什么


谢谢

看起来您有导入冲突。路径中的某个地方有一个
pyspark.py
文件,该文件是在实际的
pyspark
包之前拾取的。

我无法重现该问题,但不明白为什么需要设置SPARK\u HOME、path和PYTHONPATH。如果pyspark是以路径启动的,那么应该已经创建了SparkContext。
如果从ipython或python开始,可以使用findspark包查找Spark并创建SparkContext

$ python
>>> import findspark
>>> findspark.init('/home/user/spark')
>>> from pyspark import SparkContext
>>> sc = SparkContext('local[4]', 'myapp')
$ python
>>> import findspark
>>> findspark.init('/home/user/spark')
>>> from pyspark import SparkContext
>>> sc = SparkContext('local[4]', 'myapp')