"venv activate" doesn't not change my Python path

Viewed 2609

I create a virtual environment; let's say test_venv, and I activate it. All successful.

HOWEVER, the path of the Python Interpreter doesn't not change. I have illustrated the situation below.

For clarification, the python path SHOULD BE ~/Desktop/test_venv/bin/python.

>>> python3 -m venv Desktop/test_venv

>>> source Desktop/test_venv/bin/activate

(test_venv) >>> which python
/usr/bin/python 
2 Answers

It is not an answer specifically to your question, but it corresponds the title of the question. I faced similar problem and couldn't find solution on Internet. Maybe someone use my experience.

I created virtual environment for my python project. Some time later my python interpreter also stopped changing after virtual environment activation. Similar to how you described.

My problem was that I moved the project folder to a different directory some time ago. And if I return the folder to its original directory, then everything starts working again.

There is following problem resolution. You save all package requirements (for example, using 'pip freeze' or 'poetry') and remove 'venv'-folder (or in your case 'test_venv'-folder). After that we create virtual environment again, activate it and install all requirements.

This approach resolved my problem.

Please make sure to read Note #2.


This is what you should do if you don't want to create a new virtual environment:

In venv/bin folder there are 3 files that store your venv path explicitly and if the path is wrong they take the normal python path so you should change the path there to your new path.

change: set -gx VIRTUAL_ENV "what/ever/path/you/need" in activate.fish

change: VIRTUAL_ENV="what/ever/path/you/need" in activate

change: setenv VIRTUAL_ENV "what/ever/path/you/need" in activate.csh

Note #1:
the path is to /venv and not to /venv/bin

Note #2:
If you reached this page it means that you are probably not following Python's best practice for a project structure. If you were, the process of creating a new virtual environment was just a matter of one command line.

Please consider using one of the following methods:

Thanks you Khalaimov Dmitrii, I didn't thought it was because I moved the folder.

Related