Pycharm not installing new packages in venv if inheriting global site packages

Answered

Hey,

I'm testing virtual environenment. So I create a new project (without inheriting global site packages). I can see that listing stuff etc... shows nothing is inherited from global packages. I can install a local/virtual package in that project (say numpy) and that works fine. I install something locally - say sklearn. I list again and I see that my new package is install in that environment. If I step back and pip3 --list on my SYSTEM's pip3, then I see that sklearn is not available. So I can see that my virtual env is actually contain to my project, as expected.

Then I create another project, everything the same BUT I selected "inherit global site packages". I again list everything that I have access to (with sys.getsitepackages()) and I see that my system's packages are all there. As expected up to now.

However, if I go to settings in that project & try to install a package with Pycharm I get an error:

Error: Traceback (most recent call last):
File "/opt/pycharm-community-2018.3.5/helpers/packaging_tool.py", line 73, in run_pip
runpy.run_module(module_name, run_name='__main__', alter_sys=True)
File "/usr/lib/python3.6/runpy.py", line 201, in run_module
mod_name, mod_spec, code = _get_module_details(mod_name)
File "/usr/lib/python3.6/runpy.py", line 142, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "/usr/lib/python3.6/runpy.py", line 109, in _get_module_details
__import__(pkg_name)
File "/usr/lib/python3/dist-packages/pip/__init__.py", line 29, in <module>
from pip.utils import get_installed_distributions, get_prog
File "/usr/lib/python3/dist-packages/pip/utils/__init__.py", line 30, in <module>
from pip._vendor.retrying import retry
ModuleNotFoundError: No module named 'pip._vendor.retrying'

It then suggests me to try to install the package with the system's pip.

Well, doah.... I'm using venv because I want those localized, not so I get an extra venv folder but then still have to pollute my system's site-packages with that project's dependancies. So either something's wrong with my setup, or my conception of what a virtual environement should do is off.

What I expected:

I expected that Pycharm would install that depencides locally. I would expect to see it (along with all global site packages) if I do pip list in that virtual env. I would expect to see the same thing EXEPT that new packages if I do pip-list in the system.

1 comment

Hi Francis,

You are right to think that if you create a virtualenv in PyCharm with "inherit global site packages" option checked, then it will have the same set of packages (as at the moment of creation) as Base interpreter you chose. After that, installing packages to the system interpreter (the one you used to create virtualenv) doesn't install them to your virtualenv. And installing some package to your venv doesn't install them to your system interpreter as well.

As about the problem with package installation in PyCharm - you should try installing the same package from the system terminal (outside of PyCharm) using the same interpreter (venv in your case). Does the same error appear?

0

Please sign in to leave a comment.