在python shell中导入pyspark [英] importing pyspark in python shell

查看:40
本文介绍了在python shell中导入pyspark的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是别人在另一个论坛上的问题的副本,但从未有人回答过,所以我想我会在这里重新提问,因为我有同样的问题.(见http://geekple.com/blogs/feeds/Xgzu7/posts/351703064084736)em>

我在我的机器上正确安装了 Spark,并且在使用 ./bin/pyspark 作为我的 python 解释器时能够使用 pyspark 模块运行 python 程序而不会出错.

I have Spark installed properly on my machine and am able to run python programs with the pyspark modules without error when using ./bin/pyspark as my python interpreter.

但是,当我尝试运行常规 Python shell 时,当我尝试导入 pyspark 模块时,我收到此错误:

However, when I attempt to run the regular Python shell, when I try to import pyspark modules I get this error:

from pyspark import SparkContext

它说

"No module named pyspark".

我该如何解决这个问题?是否需要设置一个环境变量来将 Python 指向 pyspark 头文件/库/等?如果我的 spark 安装是/spark/,我需要包含哪些 pyspark 路径?还是只能从 pyspark 解释器运行 pyspark 程序?

How can I fix this? Is there an environment variable I need to set to point Python to the pyspark headers/libraries/etc.? If my spark installation is /spark/, which pyspark paths do I need to include? Or can pyspark programs only be run from the pyspark interpreter?

推荐答案

结果是 pyspark bin 正在加载 python 并自动加载正确的库路径.查看 $SPARK_HOME/bin/pyspark :

Turns out that the pyspark bin is LOADING python and automatically loading the correct library paths. Check out $SPARK_HOME/bin/pyspark :

# Add the PySpark classes to the Python path:
export PYTHONPATH=$SPARK_HOME/python/:$PYTHONPATH

我将此行添加到我的 .bashrc 文件中,现在可以正确找到模块!

I added this line to my .bashrc file and the modules are now correctly found!

这篇关于在python shell中导入pyspark的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆