0

There are many similar versions of this question; however they all seem to be caused by different scenarios than my own, and the answers are not applicable here. Running Python 3.6.5.

venv does not install pip into new environments

When I use python3 -m venv new_env, pip should normally be installed in new_env/bin. However, in my case, this does not happen, and ls new_env/bin only contains the activate scripts and python/python3.

As a result, I am still on my system's pip, i.e. which pip produces:

/usr/bin/pip

and this version of pip cannot install into my virtual environment (I can't use it at all since I don't have the permissions to change the main system folders). Similarly, pip3 is in a different but still system-wide folder (company specific).

In contrast, running which python produces:

~/new_env/bin/python3

as it should.

python -m ensurepip doesn't work, as it detects that pip is already installed on my machine (and I don't have permission to reinstall it).

Leads to errors when trying to install packages

When trying to install new packages, pip will try to install in the system folders where you may not have permission, leading to errors such as:

ERROR: Could not install packages due to an OSError: [Errno 13] Permission denied: '/somepath/lib64/python3.6/site-packages/numpy'

which may help people suffering from this problem to navigate to this question.

virtualenv does install pip

I can create a new virtual environment with

virtualenv -p python3 new_env

and this does install pip, setuptools, etc... as expected. This is a workaround for the problems above, but I still want to know why the above isn't working.

Marses
  • 1,464
  • 3
  • 23
  • 40
  • Do you see pip files in `new_env/lib/python3.6/site-packages/`? – wim May 05 '21 at 17:15
  • No, it's empty from the start. – Marses May 05 '21 at 17:17
  • import ensurepip and find the location of the package directory with `ensurepip.__path__[0]`. Do you see a `_bundled` subdirectory with wheel files contained? – wim May 05 '21 at 17:37
  • Hmm no, all I see in `ensurepip.__path__` is `['/usr/lib64/python3.6/ensurepip']` (in the virtual env created by venv). – Marses May 05 '21 at 17:43
  • I mean look inside that directory, the `ensurepip.__path__[0]` is just showing the location of the directory on your platform. – wim May 05 '21 at 17:53
  • Ah right. I see `pip-9.0.3-py2.py3-none-any.whl` and `setuptools-39.0.1-py2.py3-none-any.whl` – Marses May 05 '21 at 18:29
  • Haven't used virtualenv for a while.Tried using today and this shit. Last thing that worked for you doesn't work for me. A pip package is installed but `python3 -m pip install ` just installs the package locally - outside of the activated virtualenv. – spinkus Dec 16 '22 at 06:13
  • Found solution for my case -- https://stackoverflow.com/a/74820903/2038383. – spinkus Dec 16 '22 at 06:30

0 Answers0