Avoid the creation of multiple Jupyter kernels for each virtualenv

Viewed 72

I am working with Jupyter Notebooks and several virtualenvs in Ubuntu 18.04 (I'm not using Conda).

I usually create a new virtualenv for each new python project I'm working on and since I'm working on many projects I would like to AVOID the creation of multiple Jupyter kernels as suggested here.

Instead, I would like to tell Jupyter to start the python kernels in the virtualenv in which I am running it BY DEFAULT.

I know this is possible since it is the way it used to work, but then I don't know what I did wrong and now if I don't create a kernel for each virtualenv Jupyter doesn't allow me to use the python modules I have installed in that environment.

The way it used to work was the following:

  • I activate the virtualenv

    source bin/activate

  • I installed Jupyter in that virtualenv
  • I ran Jupyter in that virtualenv

    jupyter notebook

  • I selected Python3/2, R kernel depending on what I needed
  • I could import all the modules installed in that virtualenv

Now it's not working anymore and if I try to import a module installed in that virtualenv it gives me the following error:

ModuleNotFoundError: No module named 'modulename'

Even if I checked that the Jupyter notebook it's looking in the right paths:

! which python
/home/user/venv_name/bin/python

and

! which pip
/home/user/venv_name/bin/pip

How can I bring back the old setting?

0 Answers
Related