Skip to content

Recommend a default cross platform virtual environment management tool #118

Closed

Description

@ncoghlan

(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

  1. ncoghlan commented on Nov 20, 2014

    @ncoghlan
    ContributorAuthor

    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)

  2. dstufft commented on Nov 20, 2014

    @dstufft
    Member

    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 $PATH in 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 $PATH in 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/bin last in the $PATH, where I would say it should go before /usr/bin as I generally install things there as an override to what the system has installed).

  3. ncoghlan commented on Nov 20, 2014

    @ncoghlan
    ContributorAuthor

    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.

  4. dstufft commented on Nov 20, 2014

    @dstufft
    Member

    Huh? The problem is it adds things to the start of $PATH in 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/bin on the start of $PATH.

  5. ncoghlan commented on Nov 20, 2014

    @ncoghlan
    ContributorAuthor

    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.

  6. ncoghlan commented on Nov 20, 2014

    @ncoghlan
    ContributorAuthor

    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.

  7. dstufft commented on Nov 20, 2014

    @dstufft
    Member

    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" > ~/.zshrc or echo "PATH=$HOME/.local/bin" > ~/.zprofile. There was zero way I could find to put something ahead of the system /usr/bin that didn't also break the way vex works.

  8. dstufft commented on Nov 20, 2014

    @dstufft
    Member

    That approach is essentially saying "you're wrong for wanting pip install --user foo to override the system install of foo".

  9. ncoghlan commented on Nov 20, 2014

    @ncoghlan
    ContributorAuthor

    That sounds like a real bug report against vex then.

  10. ncoghlan commented on Nov 20, 2014

    @ncoghlan
    ContributorAuthor

    Although your examples there are taking /usr/bin off the PATH, not putting the local directory before it.

  11. dstufft commented on Nov 20, 2014

    @dstufft
    Member

    Er, I just mistyped that, I really meant echo "PATH=$HOME/.local/bin:$PATH" > ~/.zshrc

  12. ncoghlan commented on Nov 20, 2014

    @ncoghlan
    ContributorAuthor

    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
    /home/ncoghlan/.virtualenvs/misc/bin/python
    [ncoghlan@lancre py3k]$ PATH=
    /.local/bin:$PATH vex misc bash -c 'which python'
    /home/ncoghlan/.virtualenvs/misc/bin/python

  13. dstufft commented on Nov 20, 2014

    @dstufft
    Member

    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!).

  14. dstufft commented on Nov 20, 2014

    @dstufft
    Member

    Yes there is a difference, because the startup files get run after inheritance inside the subshell.

  15. ncoghlan commented on Nov 20, 2014

    @ncoghlan
    ContributorAuthor

    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.

  16. 10 remaining items

  17. ncoghlan commented on Nov 23, 2014

    @ncoghlan
    ContributorAuthor

    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.

  18. changed the title [-]Mention "vex" somewhere (at least in the "Other projects" section)[/-] [+]Recommend a default cross platform virtual environment management tool[/+] on Nov 23, 2014
  19. r1chardj0n3s commented on Nov 23, 2014

    @r1chardj0n3s
    Contributor

    +1 on @ncoghlan's comment about the scope and us providing useful recommendations.

  20. Ivoz commented on Dec 6, 2014

    @Ivoz
    Contributor

    @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.

  21. ncoghlan commented on Dec 6, 2014

    @ncoghlan
    ContributorAuthor

    @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)

  22. berdario commented on Dec 26, 2014

    @berdario

    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:

    • deadsnakes ppa or pythonz, or pyenv
    • something for scaffolding (never used one for python, but I'd probably use one if it'd come included in some other tool)
    • virtualenv + (possibly) pew | vex | virtualenvwrapper
    • tox

    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)

  23. ncoghlan commented on Jul 25, 2017

    @ncoghlan
    ContributorAuthor

    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 vex regularly, and the creation of pipenv last year.

    The key point is that while I still like vex for my own use, the fact that it doesn't follow the same traditional <tool> <subcommand> structure that pip uses is a problem from a learnability perspective.

    The fact that pew supports operations like pew inall pip install --upgrade pip setuptools wheel, and pew add for sharing content between virtual environments are also major points in its favour.

    We also know from pipenv that pew is viable as a building block for higher level more opinionated environment management tools.

    So I think the way forward here would be to:

    • draft a new entry in the Guides section covering "Managing virtual environments"
    • recommend pew as a cross-platform virtual environment manager that will work with any Python runtime, regardless of how it was installed
    • explicitly note that the optional runtime installation support doesn't currently work on Windows
    • explicitly mention pyenv & conda as more opinionated environment managers that only work with the runtimes they provide themselves
  24. theacodes commented on Jul 25, 2017

    @theacodes
    Contributor

    @ncoghlan Sounds good to me - happy to review but I won't have time to author this anytime soon.

  25. pfmoore commented on Jul 25, 2017

    @pfmoore
    Member

    @ncoghlan Do we have confirmation that pew works 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 the pew developers 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 in pew, 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 pew again, but life's pretty hectic at the moment, so I can't promise.

  26. pfmoore commented on Jul 25, 2017

    @pfmoore
    Member

    Apologies - please ignore the above comment, I was getting confused between pew and pex. I've got no reason to believe there's any issue with the Windows support of pew.

  27. ncoghlan commented on Jul 25, 2017

    @ncoghlan
    ContributorAuthor

    @pfmoore As far as I know, the one known-missing piece on Windows is the lack of pew install support for Python runtime management (since the underlying pythonz library 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 install in Windows (e.g. resolving the limitation in pythonz, or perhaps finding a way to use the pre-built conda binaries).

    However, all the virtual environment managements features work (and are tested on Appveyor).

  28. pfmoore commented on Jul 25, 2017

    @pfmoore
    Member

    Cool - sorry for the noise.

  29. ncoghlan commented on Aug 24, 2017

    @ncoghlan
    ContributorAuthor

    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-tools or pipenv either, 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.

  30. ncoghlan commented on Sep 28, 2017

    @ncoghlan
    ContributorAuthor

    I'm going to close this as:

    1. Add a new tutorial on installing packages #369 added a new tutorial that will recommend pipenv as the starting point for new users, rather than raw pip
    2. pipenv not only integrates with pew for virtual environment management, but also integrates with pyenv for language runtime management

    That 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 pipenv repo, with actual Windows users and folks like @zooba considering whether it makes the most sense to try to add Windows support to pyenv itself, or to instead create a Windows-specific backend, and have pipenv use that. (I'm not going to file that issue though, since my Windows machine is pretty much solely for games these days)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions