Israel Obando Cisneros
Israel Obando Cisneros

Reputation: 483

Jupyter Notebook and virtualenv

I have installed Jupyter notebook and use it with a virtualenv, I already have installed some packages in python but when I run in Jupyter notebook for example import numpy as np, I have a issue, module not found, there are a way to connect all of my python installed packages with Jupyter notebook?

Thanks!

Upvotes: 0

Views: 2980

Answers (4)

Rex Mudanya
Rex Mudanya

Reputation: 369

To access the packages within your environment you have to register the kernel with jupyter.

  1. Switch to your virtual environment.
  2. install ipykernel pip install ipykernel
  3. pass the virtual environment name to the following command python -m ipykernel install --user --name=[name of your environment]
  4. launch jupyter jupyter notebook
  5. select your notebook
  6. In the menu under your notebook name select kernel>change kernel>[name of your environment]

As below:

enter image description here

Upvotes: 8

GA Faza
GA Faza

Reputation: 61

If you installed your packages in python and launched your jupyter notebook from your virtualenv, you cannot import those installed packages because virtualenv created an isolated Python environment. You can read about virtualenv here.

There are two ways to resolve your problem:

  1. Launch jupyter notebook without virtualenv (simply type jupyter notebook in your terminal / command prompt)

  2. Install those packages inside your virtual environment.

Upvotes: 0

csoham
csoham

Reputation: 140

The jupyter notebook command may not be referencing to the jupyter installation in the virutal environment you are using. This is why even though you might have installed packages in your environment, jupyter is unable to import them because it is looking at a different place.

You could try to set up a different kernel for your environment, but I find that task to be tedious and after a while it becomes hard to keep track of your kernels.

The best way would be to start jupyter notebook with the python environment where all your modules are installed. To do this, activate your virtual environment, and then do:

python -m jupyter notebook

This will open Jupyter with the jupyter installed in the place where your python is pointing to and it will have the packages installed there!

Upvotes: 1

89f3a1c
89f3a1c

Reputation: 1488

There are two things to consider:

  1. Have you installed those modules inside the virtual env?
  2. Are you launching jupyter from inside the virtual env?

If you perform those actions correctly, then the error should go away.

Hope this help!

Upvotes: 0

Related Questions