I misspelled the name of the virtualenv
while initializing it using:
$ virtualenv vnev
I actually intended to create the envir
My answer is similar to creating a new virtual environment with the dependencies of the old one, but this one is succinct.
Clone the old environment (say venv_1) to a new environment (say venv_2) using conda.
conda create -n venv_2 --clone venv_1
This creates a new environment venv_2 cloning the venv_1. Hence no separate task of getting the packages/ dependencies. Single step suffices.
Delete the old virtual environment. [This step is optional if you still want to keep the old environment]
rm -rf "fully qualified path of the old virtual environment"
So in 1/2 steps the task can be achieved.
If you use virtualenvwrapper this can be done by:
$ cpvirtualenv <wrong_name> <correct_name>
$ rmvirtualenv <wrong_name>
Also, FYI, to rename a conda virtualenvironment, check out this question.
By default virtualenv does not support the renaming of environments. It is safer to just delete the virtualenv directory and create a new one with the correct name. You can do this by:
source vnev/bin/activate
pip freeze > requirements.txt
rm -r vnev/
virtualenv venv
source venv/bin/activate
pip install -r requirements.txt
If recreating is not an option there are 3rd party tools like virtualenv-mv that might be helpful.
Alternatively you can use virtualenvwrapper which provides the cpvirtualenv
command to copy or rename virtualenvs.
In windows
I was able to easily rename my virtual environment by editing activate.bat
inside scripts\
:
Backup the original activate.bat
(I copy&pasted then renamed mine BACKUP_activate.bat
).
Right-click and edit activate.bat
.
Change VIRTUAL_ENV
variable from:
set VIRTUAL_ENV=C:\some_dir\old_venv_name
into
set VIRTUAL_ENV=C:\some_dir\new_venv_name
Change PROMPT
variable from:
set PROMPT=(old_venv_name) %PROMPT%
into
set PROMPT=(new_venv_name) %PROMPT%
Save the edited batch file
NOTE: My solution should work and save windows users
setting up new virtual environments, I have no knowledge scripting or whatsoever in linux or other operating systems