Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

virtualenvwrapper: how to update project path?

When I move a project folders I have to manually update the project path in the .project file to get the workon command to work. Is it possible to update the path automatically?

like image 771
Michael B Avatar asked Jul 22 '16 22:07

Michael B


People also ask

Can you move a VENV directory?

1 Answer. Kindly be informed that yes, it is possible to move it on the same platform. You can simply use --relocatable on an existing environment. But it will get changed based on the new location in order to call python and pip, etc.

Where is virtualenvwrapper installed?

That installation installs virtualenvwrapper in the /usr/local/bin directory.

What is the difference between virtualenv and virtualenvwrapper?

Virtualenvwrapper is a utility on top of virtualenv that adds a bunch of utilities that allow the environment folders to be created at a single place, instead of spreading around everywhere.


2 Answers

According to the docs you can use setvirtualenvproject. This will automatically move you to the project folder if you use the workon command:

bono~$: setvirtualenvproject ~/.virtualenvs/your-virtual-env/ ~/path/to/your/project

Or, as beruic mentioned, it's easier to activate the environment and move to your desired working directory first. Please note that this not always work on my system, but it is a lot easier if it does work for you:

$ workon your-virtual-env
$ cd ~/path/to/your/project
$ setvirtualenvproject

In the future it might also be handy to specify the project path for the virtualenv on creation. You have to specify the project with the -a flag.

The -a option can be used to associate an existing project directory with the new environment.

You can use it something like this:

bono~$: cd ~/your/project
bono~$: mkvirtualenv my-project -a $(pwd)

The next time you use workon you will automatically be moved to your project directory.

Alternative


If you want to automatically detect directory changes and set the correct virtualenvwrapper then and there you can have a look at this post. It's a bit too expansive to go into detail here, but I think you can find what you're looking for there if that's what you meant.
like image 147
Bono Avatar answered Sep 17 '22 14:09

Bono


You can just activate your virtual environment, go to the folder you want as project folder and call setvirtualenvproject:

$ workon [your_project]
$ cd [desired_project_folder]
$ setvirtualenvproject

Then the current folder will be set as project folder in the current virtualenv.

like image 34
beruic Avatar answered Sep 20 '22 14:09

beruic