user669132
user669132

Reputation: 189

How to link virutualenvwrapper with Jupyter notebook

I have a venv/virtualenvwrapper set up in a directory. After I start working on the venv, i then create a Jupyter notebook inside of the directory, which brings me to Jupyter's localhost browser. I then attempt to import a library, e.g. pandas, which raises the ModuleNotFoundError. I would think that if the venv is being worked on, Jupyter would link to it.

Also, I can import global libraries from pip3, just not the local ones in a venv. Is there a way to use the virtualenvwrapper library with Jupyter?

Upvotes: 1

Views: 1034

Answers (1)

user669132
user669132

Reputation: 189

I found out here I had to install ipykernel after activating the venv, then create a projectname:

​(venv) $ pip install ipykernel
(venv) $ ipython kernel install --user --name=projectname

​ After that, I went back to the Jupyter browser and change the kernel from python 3 to the projectname which is only viewable after executing the second command line above.

This works for both virtualenv and virutalenvwrapper.

The only downfall is installing ipykernel adds a lot of extra libraries to your venv pip3, but I suppose you could just install ipykernel in your global pip3 to keep from installing it in your venv.

Upvotes: 2

Related Questions