本文介绍了在MacOS Import上进行Spark安装和配置ImportError:没有名为pyspark的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在MacOS上配置apache-spark.所有在线指南都要求下载spark tar并设置一些env变量,或者使用 brew install apache-spark 然后设置一些env变量.

I'm trying to configure apache-spark on MacOS. All the online guides ask to either download the spark tar and set up some env variables or to use brew install apache-spark and then setup some env variables.

现在,我使用 brew install apache-spark 安装了apache-spark.我在终端上运行 pyspark ,并收到一条python提示符,提示安装成功.

Now I installed apache-spark using brew install apache-spark.I run pyspark in terminal and I am getting a python prompt which suggests that the installation was successful.

现在,当我尝试将pyspark 导入到我的python文件中时,我遇到错误,提示 ImportError:没有名为pyspark

Now when I try to do import pyspark into my python file, I'm facing error saying ImportError: No module named pyspark

我无法理解的最奇怪的事情是它如何能够启动pyspark的REPL并且无法将模块导入到python代码中.

The strangest thing I'm not able to understand is how is it able to start an REPL of pyspark and not able to import the module into python code.

我也尝试过进行 pip install pyspark ,但它也无法识别该模块.

I also tried doing pip install pyspark but it does not recognize the module either.

除了通过自制软件安装apache-spark之外,我还设置了以下env变量.

In addition to installing apache-spark with homebrew, I've set up following env variables.

if which java > /dev/null; then export JAVA_HOME=$(/usr/libexec/java_home); fi

if which pyspark > /dev/null; then
  export SPARK_HOME="/usr/local/Cellar/apache-spark/2.1.0/libexec/"
  export PYSPARK_SUBMIT_ARGS="--master local[2]"
fi

请提出在我的本地计算机上运行pyspark代码的设置中确切缺少的内容.

Please suggest what exactly is missing on my setup to run pyspark code on my local machine.

推荐答案

对不起,我不使用MAC,但是在上述答案旁边的linux中还有另一种方法:

sorry I dont use MAC , but there is another way in linux beside above answer:

sudo ln -s $SPARK_HOME/python/pyspark /usr/local/lib/python2.7/site-packages

Python最终将从/path/to/your/python/ site-packages 中读取模块

Python will read module from /path/to/your/python/site-packages at last

这篇关于在MacOS Import上进行Spark安装和配置ImportError:没有名为pyspark的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 17:08