Skip to content

Instantly share code, notes, and snippets.

@sergeyklay
Last active July 4, 2021 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergeyklay/5d1c84f6300c681a8b568c22881aab09 to your computer and use it in GitHub Desktop.
Save sergeyklay/5d1c84f6300c681a8b568c22881aab09 to your computer and use it in GitHub Desktop.
Multiple Python versions using pyenv and python-build

Multiple Python versions using pyenv and python-build

Installation

Install pyenv

git clone git@github.com:pyenv/pyenv.git ~/.pyenv
cd ~/.pyenv && src/configure && make -C src

Install pyenv-update (optional)

git clone git@github.com:pyenv/pyenv-update.git ~/.pyenv/plugins/pyenv-update

Install pyenv-virtualenv (optional)

git clone git@github.com:pyenv/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv

Install python-build

cd ~/.pyenv/plugins/python-build
PREFIX=$HOME/.local ./install.sh

Usage

export MAKE_OPTS=-j"$(getconf _NPROCESSORS_ONLN)"
python-build $v $(pyenv root)/versions/3.9.5/

Example of script to print install instructions for multiple Python versions:

for v in pypy3.7-7.3.4 3.10.0b1 3.9.5 3.8.10 3.7.10; do
  echo MAKE_OPTS=-j"$(getconf _NPROCESSORS_ONLN)" \
  python-build $v $(pyenv root)/versions/$v/
done

This will print lines like this:

MAKE_OPTS=-j8 python-build 3.9.5 /Users/serghei/.pyenv/versions/3.9.5/

Post install

Install packages for all Python versions

for v in pypy3.7-7.3.4 3.10.0b1 3.9.5 3.8.10 3.7.10; do
  pyenv local $v
  pyenv rehash
  pip install -U pip setuptools wheel tox
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment