Search code examples
pythonpython-3.xpippython-venvpyvenv

Python installs packages globally, even with venv


I have python and try to use Venvs (best practice yada yada yada). Whenever I install a package globally, it also installs in ALL activated virtual environments, and vice versa. What is the fix?

I installed a package 'pandas' with Pip and it worked. I then activated the venv I was working with and pip freeze and 'pandas' were in the the venv. It should not have been because I had not installed it to the virtual environment yet.

I use: MacOS and Python 3.11


Solution

  • It is likely that your Virtual Environment is accessing packages installed in base or root. Best practice is to not install any package outside of virtual environments.

    Also, I would recommend switching to Anaconda as a package manager, as it is less buggy and provides another alternative for accessing packages (using conda install).