skip to Main Content
Environment
  • Ubuntu 20.04
  • Python 3.8.10
  • Pip 20.0.2

Using pip venv to create a virtual environment in my project directory. These are the commands I am running.

python3 -m pip venv .venv # Create the virtual environment
source .venv/bin/activate 
(.venv) $ time python3 -m pip install --requirement pip_requirements.txt # Inside the venv

My pip_requirements.txt has the following dependencies listed (among others)

jupyterlab
jupyter
notebook
ipython
ipykernel

So when I try to run jupyter notebook inside the venv, this is the error I get.

(.venv) della@workstation:~/Python_scripts/email-classification$  jupyter-notebook
(.venv) della@workstation:~/Python_scripts/email-classification$  jupyter notebook
Traceback (most recent call last):
  File "/home/della/.local/bin/jupyter-notebook", line 5, in <module>
    from notebook.app import main
  File "/home/della/.local/lib/python3.8/site-packages/notebook/app.py", line 20, in <module>
    from jupyterlab.commands import (  # type:ignore[import-untyped]
ModuleNotFoundError: No module named 'jupyterlab'

Tried with both space and hyphen in jupyter notebook and I get the same result.

When I look at the path, I see two things happening the interpreter is going outside the venv to look for the executable script. Should it happen at all when venv is meant to provide isolation? How can I run jupyter inside the venv with packages available only in the venv?

More information. When I try to see the executable for jupyter, I get one inside the venv.

(.venv) della@workstation:~/Python_scripts/email-classification$ which jupyter notebook -a
/home/della/Python_scripts/email-classification/.venv/bin/jupyter

2

Answers


  1. You ought to run jupyter notebook, with a space, not hyphen.

    Login or Signup to reply.
  2. I have tried the below steps and it is working for me,

    1. Install venv:

      python3 -m venv .venv (try to create venv using this command)

    2. Install pip_requirements.txt :

      time python3 -m pip install --requirement pip_requirements.txt

    3. running this command:

      jupyter-notebook or jupyter notebook both working for me

    and also you can check this documentation also: https://jupyter.org/install

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search