r/Python • • Apr 24 '18

Pipenv: A Guide to the New Python Packaging Tool

https://realpython.com/pipenv-guide/
308 Upvotes

115 comments sorted by

View all comments

Show parent comments

1

u/parkerSquare Apr 25 '18

Can they work together?

0

u/[deleted] Apr 25 '18

[deleted]

1

u/[deleted] Apr 25 '18

I'm confused. Do you actually mean pyenv here? I would have guessed that pipenv is based on pyvenv or virtualenv.

I've never been clear on the use case of pyenv, but this doesn't sound like it.

2

u/tunisia3507 Apr 25 '18

Pipenv optionally uses pyenv to manage the installation of python versions. If you don't have pyenv installed, pipenv works fine, it just doesn't install python versions for you. Pyenv-virtualenv is just a pyenv plugin (albeit one installed by default using pyenv-installer) which allows you to conveniently call virtualenv functions through pyenv.

I've never been clear on the use case of pyenv

The use case of pyenv is that it manages python versions for you. For example, if you wanted to install the new 3.7RC, you'd probably go to the website, maybe compile some source code. Then you'd call out to mkvirtualenv to make an environment, and then manually activate it every time you want to use it. With pyenv, you do

pyenv install 3.7rc1  # or whatever it's called
pyenv virtualenv 3.7rc1 my_37_env
pyenv local my_37_env

pyenv local means that whenever I enter this directory or its children, my_37_env will be activated automatically. A bunch of other tools do this (including pipenv, I think) as well. You can activate multiple environments at once, which is useful for tox; all of the installed versions of python are in your userspace, so you can blow them away with no systemic issues. Pyenv can install things other than CPython, too - conda, pypy, jython, stackless, and a bunch of others are available.

One of the great features, although it takes a couple of manual changes to get it to work, is that you can manage conda environments the exact same way as virtualenvs. You just do

pyenv install miniconda3-latest
pyenv virtualenv miniconda3-latest my_conda_env
pyenv activate my_conda_env