Issue
On Ubuntu 20.04.5 LTS with Python 3.8 I was trying to create a venv for a project to install certain versions of dependencies. I used the usual venv command python3 -m venv venv
to create a venv in the dir venv
, and source venv/bin/activate
to activate it. However after some time I found out it didn't work as expected.
Apparently the python3 path was switched successfully but the pip didn't.
I used which python3
, which pip
and which python3 -m pip
to check.
Same for pip3
and pip3.8
. While python shows the one inside the venv dir, pip does not.
I noticed that pip is also missing from the /venv/bin/
dir, but I don't know why. On my other machine pip is included in the /venv/bin/
dir and is used after activate as I expect it to.
I didn't find a solution on similar questions on stackoverflow, hence I'm opening this one.
I tried to locate pip.conf
files as suggested in one older question on here but had none present.
I also made sure that venv/pyvenv.cfg
contains include-system-site-packages = false
.
EDIT: I also tried running python -m ensurepip
with the venv activated but it states Requirement already satisfied
and shows the path for the outside pip.
Solution
For me the reason it didn't work were some environment variables. I still want to put it here, if anyone else seems stuck on a similar issue and cannot find another working solution.
Make sure to check all set environment variables e.g. by running printenv
.
For me specifically I had to unset
every environment variable which had PYTHON in it's name.
Answered By - jost Answer Checked By - David Marino (WPSolving Volunteer)