Skip to content
Advertisement

venv dependencies are being added without being downloading

I use virtual environments in my django projects. When I create my venv, I do like this from my command line

JavaScript

This creates a folder called venv on my mac machine in my Dev folder.

After I pip install django in the venv, I use the pip list command. At this point the list only contains the default django packages. It looks like this for example:

JavaScript

Then I start my django project like this.

JavaScript

After that when I move the venv folder inside my main project folder, and run pip list again, all dependencies from previous projects are being added to the list. Now it looks like this

JavaScript

I can’t figure out why this is happening.

Advertisement

Answer

Don’t move your virtual environment after creation. See this question for motivation and explanation. You can install Django on system level and create environment only when project directory already exists to avoid this moving.

And here’s why your environment stops working after moving. Suppose (/ for simplicity) you have /myenv environment path, then after . activate your path looks like

JavaScript

Now python resolves to (which python) /myenv/bin/python.

Then you move your environment. PATH remains unchanged, but now there is no /myenv/bin directory, so python resolves to /usr/bin/python and pip to /usr/bin/pip. The fact that now pip has many packages available means that you have installed dependencies for your previous project system-wide (maybe accidentally, forgotten to activate venv). You can confirm it using pip without active venv.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement