Use pew, not virtualenvwrapper, for Python virtualenvs
planspace.org
planspace.org
For those just starting Python, I'd say just go with virtualenv. It works, it's common, and there are tons of tutorials about it. Don't feel bad about using the old mediocre libraries. And in general, learning basics isn't embarrassing.
[1] -- (https://packaging.python.org/new-tutorials/installing-and-us...)
I'm not easy to hold grudges, but such a critical low-level tool manages to break for what I see as one of the most likely server environments to run on... I hold off on converting the (annoying, but working) virtualenv(wrapper) stuff. Just not worth it, now that I spent weeks of my life handling the annoyance that is python packaging and deployment.
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 successfully on my box. The goal is to be able to send you one of my scripts along with <that-list>, then you can run "<magic> run <that-list> foo.py" on your box, and everything "just works."
That way there is literally zero configuration. I don't have to tell any tool anything, and it's effortless for you to run it with all the benefits of a virtualenv.
You could come up with a half baked decent try by using the ast module to find foo.py deps and indexing pypi for provided package names. Complexity lies in where package names might intersect, but this is a half baked try after all.
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.
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...
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.
The fundamental problem is that virtualenv scripts are not actually bound to their actual virtualenv. If you forget to activate and a script shells out in a subprocess to execute another script it will not find the version installed into the virtualenv. This should be fixed upstream but so far it doesn't look like it is.
$ python3 -m venv env
$ env/bin/pip install vrun
$ env/bin/pip install foo # assume foo depends on bar and tries to start bar via subprocess
$ env/bin/foo # fails because bar is not on the path
$ env/bin/vrun foo # works
`foo` is now executed in a process in which the virtualenv is fully activated and will find appropriate dependencies on the path if it tries to run a subprocess, etc.(I do add my virtualenv's `bin/` directory to my path, but mainly so my editor can find the right tools, so I do it from elisp instead of bin/activate in a shell)
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?
I would only use 'bin/python' directly from scripts called from cron, or other similar places.
Best part is you can't accidentally install a package in the wrong venv this way.
I hate modal systems...
also lets not forget about pip install --user !
More recent tools are Pipenv (which I've been using) and hatch - I don't think there is any One True Way since the days of virtualenvwrapper being the latest and shiniest.
If you want a really easy to use tool that doesn't require any understanding of virtualenvs, I'd look at Pipenv.
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.
FD: I'm the author
It also does envs better than most other solutions since it will prefer hardlinks which allows environmental isolation at a very small cost in terms of disc space.
Full disclosure: I work for Anaconda Inc. where I am trying my best to make package management and scientific computing easier.
And of course, it makes distribution of any application that uses shared libraries a whole lot more difficult.
Disk space is the cheapest and most abundant computing resource in 2017. If you want to make these packages more widely available, just create wheels/whatever the R equivalent is. Good, well understood, and interoperable tooling for these already exists.