Live data from Hacker News

Use pew, not virtualenvwrapper, for Python virtualenvs

planspace.org

31–40 of 57 posts

Re: Use pew, not virtualenvwrapper, for Python virtualenvs

#31
post #10
post #7

Earlier quoted context omitted.

You can use virtualenv without `bin/activate`. Just refer to `bin/python` (and other scripts in `bin/`) explicitly. Don't bring in the magic until you need it. And when you need it, consider what kind of magic you need. If you're typing `bin/` too much, do you need something that adds `bin/` to your path, or do you need to write a script for this task that saves you from having to type both `bin/` and a bunch of othe…

How do you manage dependencies? One of the best parts about virtualenv (to me at least) is that I can do pip install without infecting the rest of the system. I guess I've never looked, does virtualenv provides a bin/pip which already knows the path of the virtualenv? Does the bin/python in there come with a path that uses the project pip install?

./venv/bin/pip install package

Best part is you can't accidentally install a package in the wrong venv this way.

I hate modal systems...

Re: Use pew, not virtualenvwrapper, for Python virtualenvs

#32
post #20

Why not use pyenv + pyenv-virtualenv ? https://github.com/pyenv/pyenv https://github.com/pyenv/pyenv-virtualenv

I personally found that the way pyenv conflated python versions and environments when using this produced confusing behavior around pyenv local settings and other features. At the time I tried it, there was also some opinionated behavior going on regarding shell prompt modification, etc., that caused it not to inform my prompt theming correctly.

Ultimately, I decided I didn't really want pyenv determining how I used virtualenv, I just wanted virtualenv to work well in pyenv.

The opinionated dynamic may have changed since then, but for me the happy medium has been pyenv-virtualenvwrapper. Instead of pyenv trying to take responsibility for my virtualenv behavior, it just takes responsibility for implicitly enabling virtualenv+wrapper on any given python version on first use. That's the right split for me.

Re: Use pew, not virtualenvwrapper, for Python virtualenvs

#33

What I really want is to be able to type " foo.py", where creates a list of all necessary dependencies to run foo.py. Then " run foo.py" would automatically do whatever voodoo needs to be done to run foo.py regardless of where you run that command. The idea is that we all have global pip installations, which is great for hacking. I have a ton of Python scripts that depend on my pip installs. All my scripts run succes…

It might not be magic, but sounds a lot like zc.buildout?

http://docs.buildout.org/en/latest/

Personally, I lean towards small, simple projects that are well-served by virtualenv - but for large, complex projects I think a tool like buildout will remain necessary.

Re: Use pew, not virtualenvwrapper, for Python virtualenvs

#35

What I really want is to be able to type " foo.py", where creates a list of all necessary dependencies to run foo.py. Then " run foo.py" would automatically do whatever voodoo needs to be done to run foo.py regardless of where you run that command. The idea is that we all have global pip installations, which is great for hacking. I have a ton of Python scripts that depend on my pip installs. All my scripts run succes…

zc.buildout[1] provides this kind of magic. You put the bootstrap.py[2] inside your project to bootstrap zc.buildout itself, and run `bin/buildout` and it will do everything needed to be done as configured in the recipe/configuration file. zc.buildout is also capable of compiling C sources using hexagonit.recipe.cmmi.

The magic of zc.buildout is in the recipe which is a normal Python module that allowed zc.buildout to be extended to do plenty of things (e.g. managing supervisord[3], installing postgres[4], etc.).

[1]: http://www.buildout.org/en/latest/index.html

[2]: https://github.com/buildout/buildout/blob/9a4b330338e63992dc...

[3]: https://pypi.python.org/pypi/collective.recipe.supervisor/0....

[4]: https://pypi.python.org/pypi/birdhousebuilder.recipe.postgre...

Re: Use pew, not virtualenvwrapper, for Python virtualenvs

#36
The discussion here has quickly gotten out of hand and at the risk of causing more confusion I would like to point out that pipenv(http://docs.pipenv.org/en/latest/) seems to be the officially recommended Python packaging tool now[1], though venv and pip work too.

[1] -- (https://packaging.python.org/new-tutorials/installing-and-us...)

Re: Use pew, not virtualenvwrapper, for Python virtualenvs

#37

Why not just plain virtualenv?

Indeed do just use plain virtualenv by all means! Its by far the most mature and most widely adopted solution, I happily ignore all the esoterical "reasons" against it. All those religious arguments are just annoying, it works perfectly fine in cronjobs, systemd unit files, uwsgi services, etc.

also lets not forget about pip install --user !

Re: Use pew, not virtualenvwrapper, for Python virtualenvs

#38

What I really want is to be able to type " foo.py", where creates a list of all necessary dependencies to run foo.py. Then " run foo.py" would automatically do whatever voodoo needs to be done to run foo.py regardless of where you run that command. The idea is that we all have global pip installations, which is great for hacking. I have a ton of Python scripts that depend on my pip installs. All my scripts run succes…

You should check out fades[0]. It does exactly what you are asking for.

[0] https://github.com/PyAr/fades

Re: Use pew, not virtualenvwrapper, for Python virtualenvs

#39

What I really want is to be able to type " foo.py", where creates a list of all necessary dependencies to run foo.py. Then " run foo.py" would automatically do whatever voodoo needs to be done to run foo.py regardless of where you run that command. The idea is that we all have global pip installations, which is great for hacking. I have a ton of Python scripts that depend on my pip installs. All my scripts run succes…

Sounds almost like `pip freeze > requirements.txt`. This creates a list of all your currently-installed packages, which you can install with `pip install -r requirements.txt`.

The biggest problem with this though is that this will make the other person install _all_ your installed packages, rather than just the ones needed for the particular script.

Re: Use pew, not virtualenvwrapper, for Python virtualenvs

#40
post #22
post #6

As someone who is finally getting into Python development (via Django) after following tons of tutorials over several years: should I be using pew, virtualenvwrapper, or something else? This article is from 2015, how relevant is it today?

Most people I've met use virtualenvwrapper. It doesn't work on other shells like fish though. However, I'd simply focus on learning how virtualenv works, and use whatever tool to manage it as you feel like.

Virtualfish is amazing: https://github.com/adambrenecki/virtualfish
Post reply on HN