Repository navigation
Description
(Note: the issue scope broadened considerably over the course of the subsequent discussion. When reading the comments below, note that the early ones were responding to the original issue title and description, which are preserved below)
As you accumulate more virtual environments, it's useful to have a tool to help manage them (creating new ones, listing the ones that already exist, activating them, deactivating them, etc). virtualenvwrapper, pyenv, vex, pew - these kinds of things.
However, as with packaging tools themselves, new users are unlikely to have the knowledge they need to evaluate the trade-offs between the different tools that are available. In particular, the differences between creating a subshell (vex, pew), modifying the current shell session (virtualenvwrapper), and permanently modifying user configuration settings (pyenv) have different trade-offs in terms of the amount of assumed knowledge regarding the operation of the system shell, as well as the chances of inadvertently impacting the operation of other Python applications on the system.
Considering just those four tools, and their complexity and potential for side effects, I'd assess them as follows:
- vex: aims to be shell independent, deliberately simple execution model & UI. Subshell model minimises chance of side-effects.
- pew: aims to be shell independent, aims to provide a full featured execution model & UI (comparable functionality to virtualenvwrapper). Subshell model minimises chance of side-effects.
- virtualenvwrapper, pyenv: shell specific (written in shell code, not Python), which allows tighter integration with the shell, but also requires that the user have a greater understanding of shell programming (i.e. more than the bare essentials of "enter commands to run programs"). Altering the current shell session and/or user configuration files creates a relatively high chance of side effects on unrelated tools (potentially including system utilities and other Python applications that aren't configured to run in isolated mode).
In that context, I'd suggest that vex would be an appropriate recommendation as a minimal "getting started with environment management" solution. If a given user eventually decides they want something more configurable, or more closely integrated with their preferred shell environment, then they may want to explore pew, virtualenvwrapper or pyenv, and the packaging guide could point them in those directions (with some discussion of the associated trade-offs).
Outside the Python package management space, conda then takes the step up to being a full cross-platform platform, managing the Python runtime and arbitrary external dependencies, rather than just Python virtual environments. However, as an all-in-one solution that bundles environment management, dependency management and binary distribution, conda's operating in a different category from the more single-purpose tools being discussed here.
Original issue title: Mention "vex" somewhere (at least in the "Other projects" section)
Original issue description:
https://pypi.python.org/pypi/vex is a nice alternative to things like virtualenvwrapper that I discovered via the PyCon New Zealand lightning talks.
It works by creating new subshells, rather than trying to alter the existing one. So deactivation is just a matter of exiting from the subshell.
This is really nice, because it's shell independent, and provides all the niceties of an integrated command line application, rather than a collection of shell functions.
Activity
ncoghlan commentedon Nov 20, 2014
As far as "why vex, and not the other helpers?", it's mainly because it's much simpler. It's strictly less powerful than virtualenvwrapper, but still covers all the basics of setting up, activating and deleting environments.
https://pypi.python.org/pypi/pew is another shell independent alternative to virtualenvwrapper, although it aims to match the full virtualenvwrapper feature set much more closely.
Both vex and pew are also pure Python, unlike other POSIX only approaches like pyenv (which I don't consider particularly interesting, as they don't work in native Windows shells)
dstufft commentedon Nov 20, 2014
Note that the subshell approach is fundamentally dependent on what you do in your shell RC files. This isn't a reason in itself to discourage use but maybe it should be called out? I tried something similar to vex myself and ended up trashing it because it more or less is incompatible with pyenv because pyenv modifies the
$PATHin the RC files to put itself at the start of$PATH. vex does call this out in it's PyPI description (although it's wrong for some shells, I'm not sure about bash but for zsh I was unable to use any file to modify the$PATHin a way that didn't follow into a subshell) it seems to make it sound like the user is doing something wrong (it recommends putting~/.local/binlast in the$PATH, where I would say it should go before/usr/binas I generally install things there as an override to what the system has installed).ncoghlan commentedon Nov 20, 2014
I'd put the blame for that on pyenv (and its rbenv progenitor) being broken by design - it should have the warning, rather than vex.
dstufft commentedon Nov 20, 2014
Huh? The problem is it adds things to the start of
$PATHin the RC files, which is the only way to do that if you want the pyenv installed stuff to take precedence over system installed. The exact same problem occurs if you put$HOME/.local/binon the start of$PATH.ncoghlan commentedon Nov 20, 2014
Yes, the problem is in overriding persistently and globally the default state of the system. pyenv is the tool making global changes, not vex, thus pyenv is the tool that needs the warning.
ncoghlan commentedon Nov 20, 2014
Compare that to virtualenvwrapper which has no impact on the system if nothing is activated, and even when something is activated, it only affects that particular shell session. Ditto for vex.
dstufft commentedon Nov 20, 2014
To be clear, if my memory serves I could reproduce the problem with an otherwise empty ZSH install and doing
echo "PATH=$HOME/.local/bin" > ~/.zshrcorecho "PATH=$HOME/.local/bin" > ~/.zprofile. There was zero way I could find to put something ahead of the system/usr/binthat didn't also break the way vex works.dstufft commentedon Nov 20, 2014
That approach is essentially saying "you're wrong for wanting
pip install --user footo override the system install of foo".ncoghlan commentedon Nov 20, 2014
That sounds like a real bug report against vex then.
ncoghlan commentedon Nov 20, 2014
Although your examples there are taking /usr/bin off the PATH, not putting the local directory before it.
dstufft commentedon Nov 20, 2014
Er, I just mistyped that, I really meant echo "PATH=$HOME/.local/bin:$PATH" > ~/.zshrc
ncoghlan commentedon Nov 20, 2014
Although, unless there's some odd difference between inhering PATH from the current shell and via a startup file:
[ncoghlan@lancre py3k]$ PATH=
/.local/bin:$PATH vex misc which python/.local/bin:$PATH vex misc bash -c 'which python'/home/ncoghlan/.virtualenvs/misc/bin/python
[ncoghlan@lancre py3k]$ PATH=
/home/ncoghlan/.virtualenvs/misc/bin/python
dstufft commentedon Nov 20, 2014
Both vex and pew seem to be aware, I was mostly just raising awareness here that such an issue exists and that we might want to call it out (I don't know if we should, was just mentioning it incase we should!).
dstufft commentedon Nov 20, 2014
Yes there is a difference, because the startup files get run after inheritance inside the subshell.
ncoghlan commentedon Nov 20, 2014
Ah, roger - so the startup file will override the settings from parent shell. Although wouldn't you also need a "python" or other conflicting application in the local bin directory to actually encounter a problem?
I still think the problem there is with the approach of overriding system executables persistently and globally. And yes, with the benefit of an additional 6 years experience, I do consider the fact that Python allows overriding system packages via --user somewhat dubious - note that we don't allow that to override standard library packages. Putting user site packages last so you can only add new packages, and then requiring virtual environments for overrides would be my preferred solution today.
10 remaining items
ncoghlan commentedon Nov 23, 2014
Issue title & description have been updated to match the scope of the discussion. I've preserved the original title and description to help the comments above make more sense.
[-]Mention "vex" somewhere (at least in the "Other projects" section)[/-][+]Recommend a default cross platform virtual environment management tool[/+]r1chardj0n3s commentedon Nov 23, 2014
+1 on @ncoghlan's comment about the scope and us providing useful recommendations.
Ivoz commentedon Dec 6, 2014
@ncoghlan you might be confused by the name (which I wouldn't blame you for), but pyenv does not actually manage python virtual environments, like the other tools you are comparing here.
It manages python installations, on *nixes. So you shouldn't be comparing it to virtualenvwrapper et al, they're accomplishing different things. Indeed, pyenv also has a compatibility wrapper for virtualenvwrapper to allow both to work nicely in concert.
By the by, conda also muddies the "traditional" waters by allowing one to manage the python version ( / installation) used inside the environment it creates; whereas for the other tools managing environments and python versions would be regarded as two distinct processes.
ncoghlan commentedon Dec 6, 2014
@Ivoz Yeah, that's a fair point. conda's actually designed as a full cross-platform platform - it's useful to think of it as a user space distro (i.e. something more in the Nix vein than any of the Python specific tools)
berdario commentedon Dec 26, 2014
Uh, I just discovered that Nick Coghlan uses (or attempted to use) my tool and I felt all giggly and proud :3
Anyhow, as you probably know, since October I've added Appveyor testing to pew. While that's good news (no random breakages while making changes for linux!), the situation is not perfect. For example I haven't been able to use virtualenv-clone (and thus
pew cp) on Windows recently (but I distinctly remember it working when I first started pew): all the related tests are currently skipped.I actually was not aware of the existence of a single pew user on Windows (and before october maybe there were 0 users indeed), so: please leave some feedback! (like, installation experience... is chocolatey good enough? issues... any comments)
That said, I like the idea of promoting some development tools (be it pew, vex or any other). It seems to me that some newcomers to python don't get to appreciate how easy it is to reuse something from the pypi, and that might be also because virtualenv is an extra thing to install for them (ok, now we have venv in the stdlib, but that's just a first step).
Imho, something like clojure's leiningen would be the gold standard for such development tools: it scaffolds your new project, handle dependencies, install the compiler/runtime/interpreter (that's a library like any other for clojure), run tests...
Granted, python is different, since we cannot have multiple versions of the same library installed in the same store and it cannot be compiled like Clojure (lein doesn't need clojure to bootstrap: only Java).
To get the same thing with Python we need:
Btw, I'm also a Nix user (not 100% comfortable with it, yet) and that could solve all of these needs as well (except the scaffolding part), but it's probably a bit brash to bless it as the go-to tool for Python development.
(sorry if I went a bit off-topic with my comment: at first I wanted just to chime in)
ncoghlan commentedon Jul 25, 2017
Eep, it's kinda scary to see how long ago I started this discussion :)
Anyway, a conversation today prompted me to revisit it in light of http://www.curiousefficiency.org/posts/2016/09/python-packaging-ecosystem.html, another few years of using
vexregularly, and the creation ofpipenvlast year.The key point is that while I still like
vexfor my own use, the fact that it doesn't follow the same traditional<tool> <subcommand>structure thatpipuses is a problem from a learnability perspective.The fact that
pewsupports operations likepew inall pip install --upgrade pip setuptools wheel, andpew addfor sharing content between virtual environments are also major points in its favour.We also know from
pipenvthatpewis viable as a building block for higher level more opinionated environment management tools.So I think the way forward here would be to:
pewas a cross-platform virtual environment manager that will work with any Python runtime, regardless of how it was installedtheacodes commentedon Jul 25, 2017
@ncoghlan Sounds good to me - happy to review but I won't have time to author this anytime soon.
pfmoore commentedon Jul 25, 2017
@ncoghlan Do we have confirmation that
pewworks reliably on Windows? From what I recall, I tried it some time ago (probably way back when you originally started this discussion) and found a number of bugs. When I reported them thepewdevelopers were happy to accept patches but didn't have much in-house expertise on Windows. Having said that, I can't find those issues and the github project owner seems different, so it's possible I'm thinking of a different project. There seems to be specific support for powershell inpew, which suggests they are covering Windows specifically.I'm happy to recommend a tool, but IMO it's important that we're comfortable with its cross-platform support. I'll try to get a chance to check out
pewagain, but life's pretty hectic at the moment, so I can't promise.pfmoore commentedon Jul 25, 2017
Apologies - please ignore the above comment, I was getting confused between
pewandpex. I've got no reason to believe there's any issue with the Windows support ofpew.ncoghlan commentedon Jul 25, 2017
@pfmoore As far as I know, the one known-missing piece on Windows is the lack of
pew installsupport for Python runtime management (since the underlyingpythonzlibrary is *nix only, those features don't work on Windows).So Windows folks wanting that kind of capability are either still going to need to a full cross-platform platform like conda, or else figure out what would be needed to enable
pew installin Windows (e.g. resolving the limitation inpythonz, or perhaps finding a way to use the pre-builtcondabinaries).However, all the virtual environment managements features work (and are tested on Appveyor).
pfmoore commentedon Jul 25, 2017
Cool - sorry for the noise.
ncoghlan commentedon Aug 24, 2017
Considering my answer to https://twitter.com/ncoghlan_dev/status/900547395095625728, another notable absence from the current tooling recommendations is the fact that we don't point anyone towards
pip-toolsorpipenveither, and frankly, if you're doing professional software development with Python (as opposed to ad hoc scripting), you should probably be using either conda or one of those two options.I filed #367 for that.
ncoghlan commentedon Sep 28, 2017
I'm going to close this as:
pipenvas the starting point for new users, rather than rawpippipenvnot only integrates withpewfor virtual environment management, but also integrates withpyenvfor language runtime managementThat still leaves Windows users without an automated option for managing the language runtimes themselves (short of switching to something like conda), but that's not going to be resolved here in PyPUG, since the problem is with the tooling not existing for that (as far as we're aware), rather than our failing to guide new users through a plethora of competing options.
So probably the best place to discuss that now would be on the
pipenvrepo, with actual Windows users and folks like @zooba considering whether it makes the most sense to try to add Windows support topyenvitself, or to instead create a Windows-specific backend, and havepipenvuse that. (I'm not going to file that issue though, since my Windows machine is pretty much solely for games these days)