Before I install virtualenvwrapper, I have some virtualenv installed in different location. Is there any way to collect them in virtualenvwrapper so that appear in workon command?
-
If all else fails, you could always use `pip freeze > requirements.txt` and then create a new virtualenv. – shad0w_wa1k3r Apr 05 '17 at 06:03
1 Answers
Yes, that should be possible. Virtualenvwrapper allows you to custom define where your created environments will be stored:
export WORKON_HOME=/path/to/your/envs
If you point this to the location of your virtual environments from virtualenv, it should work. You should add this line to your .bashrc or .zshrc or whichever else shell you're using. The problem with this is that you wont be able to activate any environments that are not in that folder.
In that case it will probably work to just copy the whole virtualenv into where your virtualenvwrapper environments are created.
You can find out where that is like this:
mkvirtualenv test
workon test
which python
# Will print path to virtual python interpreter:
/path/to/virtualenvs/test/bin/python
Copy the desired environments so they are in the same folder
as the just created test environment. Here, this folder would be
/path/to/virtualenvs/
. I'll call it $VENVS
from now on.
After copying it should be something like /path/to/virtualenvs/my-other_env1
, /path/to/virtualenvs/my-other_env2
.
Assuming you created my-other_env1 and 2 before with virtualenv with default settings, copying my-other-evn1 can be done like:
cp ~/.virtualenvs/my-other-env1 $VENVS/
You can delete the test environment afterwards using
rmvirtualenv test
(Of course, if you already know what that folder is, it's not necessary to create the test environment.)

- 4,487
- 4
- 32
- 50
-
For those who can't get `which python` to work, using `lsvirtualenv` will list where they are as well as which ones are available – Jacob Zimmerman Sep 10 '17 at 20:52
-
1
-
The [documentation](https://virtualenvwrapper.readthedocs.io/en/latest/install.html#location-of-environments) says `The variable WORKON_HOME tells virtualenvwrapper where to place your virtual environments. The default is $HOME/.virtualenvs. If the directory does not exist when virtualenvwrapper is loaded, it will be created automatically.` – Mark Apr 11 '21 at 17:40
-
So TL;DR `cp existing_env_folder $WORKON_HOME` or `cp venvs/* $WORKON_HOME` – Mark Apr 11 '21 at 17:42