Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> And finally...well, I have to admit it, but I use Python like a goddamned moron in that I still don't know how to use virutalenv/venv to do proper dev isolation.

I was the same way for quite a while, until I bumped into pyenv-virtualenv[1]. Just install that plugin, and you can do, eg,

    pyenv virtualenv 3.5.1 my-project
to get a virtual environment called `my-project` based off of Python 3.5.1 (assuming that you've installed 3.5.1 via pyenv, of course). Or, you can just do

    pyenv virtualenv my-project
to make a virtualenv called `my-project` based off of the current version of Python that you're using.

Once you do that, pyenv treats `my-project` just as another installation of Python. In fact, `my-project` will show up in the list of installed versions (`pyenv versions`), and you can switch to it:

    pyenv global my-project
(Or you can switch at the local or shell levels. Whichever.)

And voila! You have your own virtual environment that can contain its own list of libraries.

And no, I'm not a shill for the creator of pyenv, I just really like the software.

[1]: https://github.com/yyuu/pyenv-virtualenv



Thanks for this...wrapping it up in pyenv is a lot more familiar to me. And why would you apologize for shilling for pyenv?...it's amazing :) (as is rbenv, its inspiration)


You're very welcome.

And ehhh, I've been downvoted and bitched at about evangelizing pyenv before. Just thought I'd preempt that. But yes, it's an amazing piece of software. :)

FYI, I've put together a bash function for my .bash_profile that adds an indicator to my prompt showing the current Python version/virtualenv in use[1]. That's saved me a bit of frustration when going into a directory where a local pyenv version overrides the global version.

[1]: https://github.com/jackmaney/bash-profile/blob/ddb57091aab44...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: