I've created folder and initialized a virtualenv instance in it.
$ mkdir myproject
$ cd myproject
$ virtualenv env
When I run (env)$ pip freeze
, it shows the installed packages as it should.
Now I want to rename myproject/
to project/
.
$ mv myproject/ project/
However, now when I run
$ . env/bin/activate
(env)$ pip freeze
it says pip is not installed. How do I rename the project folder without breaking the environment?
You need to adjust your install to use relative paths. virtualenv
provides for this with the --relocatable
option. From the docs:
Normally environments are tied to a specific path. That means that you cannot move an environment around or copy it to another computer. You can fix up an environment to make it relocatable with the command:
$ virtualenv --relocatable ENV
NOTE: ENV is the name of the virtual environment and you must run this from outside the ENV directory.
This will make some of the files created by setuptools or distribute use relative paths, and will change all the scripts to use activate_this.py instead of using the location of the Python interpreter to select the environment.
Note: you must run this after you've installed any packages into the environment. If you make an environment relocatable, then install a new package, you must run virtualenv --relocatable again.
caveat: Changing an env to relocatable does more than just let you move the folder. (see the Note: copied from the docs)... it may have side effects.
The --relocatable option currently has a number of issues, and is not guaranteed to work in all circumstances. It is possible that the option will be deprecated in a future version of virtualenv. Also, this does not make your packages cross-platform. You can move the directory around, but it can only be used on other similar computers.
@TheDemz
grep -EIr '\Wold_venv_name\W' /path/to/new_venv
will help find any shabangs that use the old venv, but is not a complete verifcation of the relocated venv.Also, you'll have to edit the virtualenvwrapper
.project
file, which contains the path to the source code that depends on the virtualenv, assuming you are using virutalenvwrapper and have also renamed the project dir to match the new virtualenv.I had to deactivate the virtualenv before running this.