0

Using Python Jupyter notebooks to work in an environment I've created. Everything went fine until I decided to add another package to the environment. After setting up the environment, I was unable to import additional packages I installed in the environment. I was only able to import packages I installed on set-up.

Here are the commands I used to create the environment initially:

python -m venv test
. test/bin/activate

pip install pyodbc
deactivate

python3 -m ipykernel install --user --name test

This all worked fine. I started a notebook using the new environment and was able to import pyodbc without error! Then I decided I wanted to add another package, geopandas.

. test/bin/activate

pip install geopandas

deactivate

I opened a notebook in the kernel and tried

import geopandas

ModuleNotFoundError                       Traceback (most recent call last)
/tmp/ipykernel_47903/1529612126.py in <module>
----> 1 import geopandas

ModuleNotFoundError: No module named 'geopandas'

I then attempted linking it to ipykernel again

python3 -m ipykernel install --user --name test

But I still received the same error in the notebook and was unable to import the package. How can I add more packages to an environment after already establishing it? I'm not sure what I'm doing wrong. Thank you!

34jbonz
  • 118
  • 8
  • Did you see [errorLogger's comment here](https://stackoverflow.com/questions/67207286/jupyter-notebook-not-recognizing-packages-in-venv#comment118814353_67207424)? Alternatively if you don't want to sort it the proper way right now ...Have you tried running in the notebook where you want to use the import statement, `%pip install geopandas`, restart the kernel after it completes, and then retry import statement? This might let you – Wayne Dec 14 '22 at 17:18
  • @Wayne unfortunately that did not work for me, though %pip install in the notebook certainly works, it just ignores the purpose of running in an environment. – 34jbonz Dec 16 '22 at 19:57
  • Yes, but you could next time set up the environment from the get-go with everything while still working now. Hopefully someone will see something missed and adding after from the command line will work. – Wayne Dec 16 '22 at 20:01

0 Answers0