Where should virtual machines be created?

I am confused about where I should put my virtualenvs.

With my first django project, I created a project using the command

django-admin.py startproject djangoproject 

Then I went to the djangoproject directory and ran the command

 virtualenv env 

which created the virtual environment directory at the same level as the djangoproject internal directory.

Is this the wrong place to create virtualenv for this particular project?

My impression is that most people store all their virtualenvs together in a completely different directory, like ~/virtualenvs , and then use virtualenvwrapper to switch between them.

Is there a proper way to do this?

+77
python virtualenv virtualenvwrapper
Aug 29 '12 at 19:04
source share
4 answers

Many people use the virtualenvwrapper tool, which supports all virtual virtual machines in the same place ( ~/.virtualenvs ) and allows you to use shortcuts to create and hold them there. For example, you can:

 mkvirtualenv djangoproject 

and then later:

 workon djangoproject 

It's probably a bad idea to keep the virtualenv directory in the project itself, because you don't want to distribute it (this may be specific to your computer or operating system). Instead, save the requirements.txt file with pip :

 pip freeze > requirements.txt 

and distribute it. This will allow others using your project to reinstall the same requirements into their virtualenv using:

 pip install -r requirements.txt 
+100
Aug 29 2018-12-12T00:
source share

Changing the location of the virtualenv directory violates it

This is the main advantage of placing the directory outside the repository tree, for example. under ~/.virtualenvs with virutalenvwrapper .

Otherwise, if you save it in the project tree, moving the project location will break the virtual file.

See: Renaming a virtualenv folder without breaking it

There is --relocatable , but as you know, it is not perfect.

Another small advantage: you do not need it .gitignore .

If this were not the case, I would simply leave my virtualenvs gitignored in the project tree itself to link related things.

This is great, since you will probably never reuse this virtualenv for projects.

+15
May 08 '16 at 14:46
source share

A common place to host is the same place as the default virtualenvwrapper installation: ~/.virtualenvs

Related: virtualenvwrapper is a great tool that provides a shorthand for common virtualenv commands. http://www.doughellmann.com/projects/virtualenvwrapper/

+4
Aug 29 2018-12-12T00:
source share

If you are using pyenv install Python , it is best to use pyenv-virtualenv . If a .python-version file is installed, it can automatically activate or deactivate virtual env when changing the working folder. Pyenv-virtualenv also places all virtual env in the $HOME/.pyenv/versions folder.

0
Jul 13 '17 at 10:16
source share



All Articles