Installing multiple dev envs on older (and maybe new - dunno) macs

older macs use python 2.7 - and you don't want to mess with it.

so how to have multiple python versions, virtualenvs and pip up and running for more than one project?

i use pyenv in combination with pipenv for quite a while now and as @santonelli asked me to document this approach for further use, here it is:

why the combo?
i had issues with only using pyenv, as somehow packages installed using pip where added to that python instead of its virtualized installation. pipenv solved that for me and i never looked back, if something changed there (so don't see this as: "this is the way" in mandalorian voice; it is simply a way)

installation

install homebrew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

install pyenv

brew install pyenv

install pipenv

brew install pipenv

zsh support

i use zsh with ohmyzsh and powerlevel10k there are autocomplete and recognition plugins that work well with both tools.

updating

by updating pyenv via homebrew, you'll get newer python versions (like 3.10.x) added to be installable using pyenv.

brew upgrade pyenv

using pyenv and pipenv

i use pyenv only to add additional python versions to my mac (you can tab-complete to see what versions are available)

pyenv install -v 3.9.7

you can list the installed versions and see which is default:

pyenv versions

  • system (set by /Users//.pyenv/version)
    2.7.18
    3.9.7

you can set a default/system python and list installed versions too, but i usually don't mess with that.

pyenv global 3.9.7

with pipenv i define local environments that install a certain python version and add python packages

pipenv install --python 3.9.7
pipenv install zc.buildout==<specific_version>

and so on...

use with core dev:

git clone https://github.com/plone/buildout.coredev
cd buildout.coredev
pipenv --python 3.9.7 run pip install -r requirements.txt

this will create a virtualenv with python 3.9.7 and install packages with specific versions inside that venv.

(on my mac using zsh - whenever i use a terminal to come back to that project folder, the virtualenv will be fired up automatically and it will be exited, when going a level up or closing that terminal. works in vscode too.)

to activate the virtualenv manually you can use:

pipenv shell

or use "pipenv run" and be exited directly after execution is done:

pipenv run pip list

as every tool has drawbacks...

i never got pipenv to recognize my requirements.txt (and in addition the constraints.txt.
also a "thing": even if pipenv gets the requirements.txt correct, it will not recognize changes in that file afterwards. you'll need to add those changes to the Pipfile generated by pipenv.

hope this helps.

please visit the linked project pages or read those articles in addition:

2 Likes