Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pyenv choose virtualenv directory

I just began to use pyenv to manage my python versions, and began to use the pyenv virtualenv plugin to manage my virtualenvs, and so far, I have loved it. One thing I miss however, is that with virtualenv, you could actually place virtual environments in repository directories so that your repository was a completely reproducible environment. Does anyone know of a way to choose the directory of your virtualenv in pyenv?

like image 328
ericmarkmartin Avatar asked May 22 '15 23:05

ericmarkmartin


People also ask

Where should I put my virtualenv?

While the tools allow you to put your virtual environments anywhere in the system, it is not a desirable thing to do. There are two options: Have one global place for them, like ~/virtualenvs . Store them in each project's directory, like ~/git/foobar/.

How do I get rid of VENV folder?

There is no command for deleting your virtual environment. Simply deactivate it and rid your application of its artifacts by recursively removing it. Note that this is the same regardless of what kind of virtual environment you are using.


2 Answers

Short answer: You can’t, as far as I know.

It wouldn’t really work either, right? If you use pyenv virtualenv to install a virtualenv into a repo, and you clone that repo to another machine… how would pyenv on the new machine know to take control of the virtualenv in the repository?

Also, “you probably shouldn’t do that”. Virtualenvs are not 100% decoupled from the underlying Python installation, and aren’t really all that portable. And do you really want to litter your repositories with a bunch of easily replicated junk? The “right” way to go about things is probably to to maintain a requirements.txt for pip — that way you can easily reproduce your development environment wherever you clone your repo.

That all said, there’s nothing stopping you from using plain old virtualenv to create a virtualenv anywhere you like, even if you installed virtualenv into a Python interpreter under pyenv control. That virtualenv itself will of course not be administered by pyenv, but you can still use it as you always did…

like image 198
wjv Avatar answered Oct 01 '22 13:10

wjv


Here is a GitHub issue on the project tracker asking about this: https://github.com/pyenv/pyenv/issues/802

The reply by a project collaborator was:

You can just create virtualenv in any location. To use it from pyenv, create symlink to the environment in ~/.pyenv/versions

although I must say I'm not very satisfied with this solution.