Melly
Melly

Reputation: 755

Cannot execute pip after changing virtualenv folder name

So previously I named my virtual environment "test". After that, I changed it to "testt", and after that I can't access pip commands anymore and it gives me the following error:

Fatal error in launcher: Unable to create process using '"C:\coding\test\test\Scripts\python.exe"  "C:\coding\test\testt\Scripts\pip.exe" ': The system cannot find the file specified.

How can I fix this?

Upvotes: 1

Views: 1401

Answers (1)

wovano
wovano

Reputation: 5091

You should never rename a virtual Python environment. When creating the virtual environment, the path is hardcoded in several places (see the Scripts/activate* scripts for example).

You could try to replace the hardcoded paths in all files, but I'm not sure how good this works and if this changes between (Python/venv) versions.

Best thing to do is just remove the old virtual environment and create a new one.

If you're using a requirements.txt file, this as as easy as:

  1. py -3.10 -m venv new_env
  2. new_env\Scripts\python.exe -m pip install -r requirements.txt

(example commands are for Windows and Python 3.10, but are similiar for Linux and/or other Python versions)

If you didn't use a requirements.txt file, you could run pip freeze before removing the old virtual environment to see which modules you had installed.

Side note: this method has the advantage that you're actually verifying that your environment is well documented (i.e., the requirements.txt is up-to-date) and that you can reproduce it. This will make it easier to repeat this process in the future (e.g. on another computer) as well.

Upvotes: 2

Related Questions