pip fails in my python virtual environments

Viewed 371

Trying to follow this tutorial: https://docs.python.org/3/tutorial/venv.html.

$ python3 -m venv tutorial-env

$ source tutorial-env/bin/activate

so far so good, however:

(tutorial-env) $ pip --version
import: not authorized `re' @ error/constitute.c/WriteImage/1028.
import: not authorized `sys' @ error/constitute.c/WriteImage/1028.
from: can't read /var/mail/pip
~/src/examples/tutorial-env/bin/pip: line 10: syntax error near unexpected token `('
~/src/examples/tutorial-env/bin/pip: line 10: `    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])'

tells me something must be wrong with my python installation. I assume that should have worked.

Some information about my system installation, and the version of the software used to create that tutorial-env environment:

(tutorial-env) $ deactivate

$ which python3 && python3 --version
/usr/bin/python3
Python 3.5.2

$ python3 -m pip --version
pip 20.2.3 from ~/.local/lib/python3.5/site-packages/pip (python 3.5)

That does not seem right to me. Perhaps the problem is rooted in /usr/bin/python3 -m pip using dependencies under ~/.local/lib when I would have expected it to depend on /usr/local/lib/python3.5/dist-packages/pip. I'm not entirely sure this is the root cause though, perhaps I just don't know how to start a virtual environment.

Update: Looking carefully, I see that /usr/local/lib/python3.5/dist-packages does not contain a pip folder, whereas /usr/local/lib/python2.7/dist-packages by comparison does. Perhaps that is the root cause. However I have installed python3-pip via apt-get install.

1 Answers

Try re-installing both python and the virtual environment in that order

Related