With an active venv, "pip install -r requirements.txt" is installing to the global environment while "pip install pandas" installs to the install to active venv.
Environment
- Ubuntu 20.04.6
- Installed python 3.9
I created and activated a virtual environment using:
python3.9 -m venv .venv
source .venv/bin/activate
I see the terminal line begin with (.venv) and which pip
and which python
both seem to point to what is in .venv.
Main issue
When I run
python3.9 -m pip install pandas
pip list
I get the expected output with pandas listed as an installed package.
When I run
python3.9 -m pip install -r requirements.txt
python3.9 -m pip list
I see none of the packages from my requirements.txt.
Finally, if I run
deactivate
python3.9 -m pip list
I see everything got installed to the global environment.
Does anyone know what could be going on?
2
Answers
Partially figured it out.
Looks like pip could not find one of the packages since I did pip freeze > requirements.txt on a windows machine and it will not do install anything if it fails to install everything from a requirements file.
I am not sure how I ended up with things installed to my global environment but everything worked as expected once I removed the windows specific package.
Which 🐍 python version do you have installed in your machine? Probably it’s something about pip and pip3.
💡Try :