Create a copy of virtualenv locally without pip install
First way to create a copy of existing virtualenv, say ProjectAenv
:
-
Copy the ProjectAenv to some other name or directory:
cp -R /home/sk/Path1/ProjectAenv /home/sk/Path2/ProjectBenv
where
/home/sk/Path1/ProjectAenv
is the absolute path of the virtualenv ProjectAenv -
Then open the
activate
file of newly copied ProjectBenv using your preferred editor:gedit /home/sk/Path2/ProjectBenv/bin/activate
-
Find the line VIRTUAL_ENV="/home/sk/Path1/ProjectAenv" and replace it with:
VIRTUAL_ENV="/home/sk/Path2/ProjectBenv"
Save and close the file.
Thats it!! Your new environment ProjectBenv is copied from ProjectAenv and ready to use. I'm using this way for a long time and never got any issues yet, although I recommend the 2nd way of copying.
Second way to create a copy of existing virtualenv(Recommended):
-
Download virtualenv-clone:
wget https://pypi.python.org/packages/source/v/virtualenv-clone/virtualenv-clone-0.2.6.tar.gz tar -zxvf virtualenv-clone-0.2.6.tar.gz cd virtualenv-clone-0.2.6
-
Install virtualenv-clone inside any virtualenv environment:
virtualenv newenv # create a new environment. You can use any existing one. source newenv/bin/activate # login to newenv (newenv): python setup.py install # install virtualenv-clone in newenv # be sure that you are inside the directory "virtualenv-clone-0.2.6"
virtualenv-clone
will be installed inside newenv. -
Now while logged-in as newenv we can create a copy of any existing environment. For example creating the copy of ProjectAenv:
(newenv): virtualenv-clone ProjectAenv ProjectBenv (newenv): deactivate # to come out from newenv.
Please comment for any suggestions or changes.
Just want to add to the manual method of @SauravKumar. Fixing the path in the activate
script is necessary, but not sufficient. You also need to fix the path in other scripts like pip
, pip2
, etc.
The easiest thing to do is search for your path inside the virtual environment bin
folder like:
root@www:/var/www/app/venv/bin# grep "/tmp/app/HadithHouseWebsite/venv" * -R
activate:VIRTUAL_ENV="/tmp/app/HadithHouseWebsite/venv"
activate.csh:setenv VIRTUAL_ENV "/tmp/app/HadithHouseWebsite/venv"
activate.fish:set -gx VIRTUAL_ENV "/tmp/app/HadithHouseWebsite/venv"
django-admin:#!/tmp/app/HadithHouseWebsite/venv/bin/python2.7
django-admin.py:#!/tmp/app/HadithHouseWebsite/venv/bin/python2.7
easy_install:#!/tmp/app/HadithHouseWebsite/venv/bin/python2.7
easy_install-2.7:#!/tmp/app/HadithHouseWebsite/venv/bin/python2.7
pbr:#!/tmp/app/HadithHouseWebsite/venv/bin/python2.7
pip:#!/tmp/app/HadithHouseWebsite/venv/bin/python2.7
pip2:#!/tmp/app/HadithHouseWebsite/venv/bin/python2.7
pip2.7:#!/tmp/app/HadithHouseWebsite/venv/bin/python2.7
python-config:#!/tmp/app/HadithHouseWebsite/venv/bin/python
sqlformat:#!/tmp/app/HadithHouseWebsite/venv/bin/python2.7
wheel:#!/tmp/app/HadithHouseWebsite/venv/bin/python2.7
Then go through these files and change the ones you need. Mostly you need to change the activate*
files and pip*
files.
Hope this helps.