【发布时间】:2021-07-13 02:34:38
【问题描述】:
总结
我正在尝试在一个全火花笔记本中执行this simple python code snippet,该笔记本应该在我在this docker-compose file 中设置的本地火花集群中执行。但是,我收到了错误 ModuleNotFoundError: No module named 'pyspark',这对我来说没有意义,因为在 this Dockerfile(我从 docker repos documentation 中获取)中,我使用 pip 明确安装了 pyspark。
重现错误的步骤
# Clone the repository and checkout a specific commit
kevinsuedmersen@LAPTOP-XXX:~/dev/hadoop-sandbox$ git clone https://github.com/kevinsuedmersen/hadoop-sandbox.git
kevinsuedmersen@LAPTOP-XXX:~/dev/hadoop-sandbox$ git checkout e0a061dd3a60842aa0e93893892c7e0844c2278a
# Install and start all services
kevinsuedmersen@LAPTOP-XXX:~/dev/hadoop-sandbox$ docker-compose up -d
# Entering the container running the notebooks
kevinsuedmersen@LAPTOP-XXX:~/dev/hadoop-sandbox$ docker exec -it jupyter-spark bash
# Activating the custom python environment installed in the above referenced Dockerfile
(base) jovyan@XXX:~$ conda activate python37
# Start a jupyter notebook server
(python37) jovyan@XXX:~$ jupyter notebook
# After some logging, the following output shows
To access the notebook, open this file in a browser:
file:///home/jovyan/.local/share/jupyter/runtime/nbserver-27913-open.html
Or copy and paste one of these URLs:
http://b8ef36545270:8889/?token=some_token
or http://127.0.0.1:8889/?token=some_token
然后,我点击 URL http://127.0.0.1:8889/?token=some_token 在浏览器中打开 jupyter GUI,执行 the simple python code snippet 并得到上述错误。
我尝试过的
为了检查 pyspark 是否真的安装了,我基本上只是尝试在 jupyter-spark 容器的 shell 中执行the simple python code snippet,令人惊讶的是,它起作用了。具体来说,我在一个新的 shell 中执行了以下命令:
# Entering into the jupyter-spark container and activating the custom python environment
kevinsuedmersen@LAPTOP-XXX:~/dev/hadoop-sandbox$ docker exec -it jupyter-spark bash
(base) jovyan@XXX:~$ conda activate python37
# Opening a python shell
(python37) jovyan@XXX:~$ python
# Copy pasting the same commands from the notebook into the shell
>>> import pyspark
>>> from pyspark.sql import SparkSession
>>> spark = SparkSession.builder.master('spark://spark-master:7077').getOrCreate()
>>> sc = spark.sparkContext
>>> rdd = sc.parallelize(range(100 + 1))
>>> rdd.sum()
5050
此外,我注意到在笔记本中执行以下操作
! python --version
打印Python 3.8.8
那么,我的问题是:我怎样才能让 notebook 使用自定义的 python 环境?
【问题讨论】:
标签: docker apache-spark hadoop pyspark jupyter-notebook