Running Jupyter notebook in a virtualenv: installed sklearn module not available

前端 未结 7 2196
小蘑菇
小蘑菇 2020-12-13 09:33

I have installed a created a virtualenv machinelearn and installed a few python modules (pandas, scipy and sklearn) in that environment.

When I run

7条回答
  •  暖寄归人
    2020-12-13 10:26

    Creation of virtualenv with python3 -m venv command

    I had the same problem as yours. In my case I had created the virtualenv with the command

    python3 -m venv ./my_virtual_env --system-site-packages
    

    The problem was I could not install jupyter inside the virtual environment as it was already in the system-site-package (when you try to install it, it tells you "Requirement already satisfied").

    To install jupyter, (and in a first instance pip, that does not get installed neither in your virtual environment with this command) but still have access to system-site-package you can run :

    python3 -m venv ./my_virtual_env
    

    Activate you virtual environment, run pip3 install jupyter (and pip3 install pip) and then turn on the option include-system-site-packages in the file ./my_virtual_env/pyvenv.cfg.

    After deactivation and reactivation of you environment, you will have access to system site-packages.

    Creation of virtualenv with virtualenv command

    Given this answer you can prevent the access to system site-packages by creating a file ./my_virtual_env/lib/python3.4/no-global-site-packages.txt, and get the access back by removing it.

提交回复
热议问题