Summary
I am trying to execute this simple python code snippet in an all-spark-notebook which is supposed to be executed in a local spark cluster which I setup in this docker-compose file. However, I am getting the error ModuleNotFoundError: No module named 'pyspark' which doesn't make sense to me, because in this Dockerfile (which I took from the docker repos documentation) I explicitly installed pyspark with pip.
Steps to reproduce the error
# 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
Then, I click on the URL http://127.0.0.1:8889/?token=some_token to open up the jupyter GUI in my browser, execute the simple python code snippet and get the above error as explained above.
What I've tried
To check if pyspark was really installed, I basically just tried to execute the simple python code snippet in the shell of the jupyter-spark container and surprisingly, it worked. Specifically, I executed the following commands in a new 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
Furthermore, I noticed that executing the following in the notebook
! python --version
prints Python 3.8.8
So, my question is: How can I make the notebook use the custom python environment?