Skip to content

How to use pyenv to manage multiple Python versions on Ubuntu/Mac #249

@cztomczak

Description

@cztomczak

Tested with Ubuntu 14.04 and Mac 10.9.

pyenv: https://github.com/yyuu/pyenv

Install on Linux: https://github.com/yyuu/pyenv-installer

Don't forget dependencies on Linux: https://github.com/pyenv/pyenv/wiki/common-build-problems

Install on Mac with Homebrew: https://github.com/yyuu/pyenv#homebrew-on-mac-os-x

Add pyenv to ~/.bashrc . Do not add the eval "$(pyenv virtualenv-init -)" line otherwise pyenv is broken then.

.bashrc for Linux:

export PYTHON_CONFIGURE_OPTS="--enable-shared"
export PATH="/home/cz/.pyenv/bin:$PATH"
eval "$(pyenv init -)"

.bash_profile for Mac:

export PYTHON_CONFIGURE_OPTS="--enable-framework"
export PATH="/usr/local/bin:/usr/local/git/bin:$PATH"
eval "$(pyenv init -)"

Python must be built as shared library on Linux and as framework on Mac

Python must be built as shared library on Linux, and as framework on Mac. See this explanation by Robin Dunn: wxWidgets/Phoenix#288 (comment)

Build options explained on pyenv wiki page:
https://github.com/pyenv/pyenv/wiki#how-to-build-cpython-with-framework-support-on-os-x
https://github.com/pyenv/pyenv/wiki#how-to-build-cpython-with---enable-shared

Continued

Install multiple Pythons. Before proceeding install required packages listed here: https://github.com/yyuu/pyenv/wiki/Common-build-problems

pyenv install --list
pyenv install 3.4.5
pyenv install 3.5.2

Change Python version in current terminal (shell), in current directory (local, creates .python-local file) or globally (global):

pyenv shell 3.4.5
pyenv local 3.4.5
pyenv global 3.4.5  <-- using global is recommended

Issue with sudo

It doesn't work with sudo. But it shouldn't matter, because when installing python package you don't need to use sudo, as Python is installed in ~/.pyenv and doesn't require root privileges.

Update pyenv

You need to update pyenv so that you can install new Python versions available. When executing pyenv install --list I didn't see latest Py 3.6 rc1. I had to run pyenv update to be able to install it.

Homebrew

Mac notes for Homebrew:

  • Install GUI toolkits for the Homebrew Python: brew install python, brew install wxpython, brew install pygtk, brew install gtk+3 pygobject3, etc.
  • To install GUI toolkits for Homebrew's Python 3 type: brew install python3, brew install gtk+3 pygobject3 --with-python3.
  • To install PySide for Qt4 type: install Qt 4.8.5 dmg and type sudo pip install pyside==1.2.2. If there are errors when importing library add pyside directory to DYLD_LIBRARY_PATH or run the pyside postinstall script manually (find it on the web).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions