Skip to content

Install Python using Pyenv

Abstract

The idea is this: your laptop comes in with a system level installed python. You do no want to mess that installation. Instead the steps described hereafter will make you install a correct python3 setup.

Note also that you need python for several different use cases: * compiling the official documentation (pp-punch/pp-documentation) * compiling and running python applications (pp-punch/pp-python) * compiling and running the punch elasticsearch housekeeping service (pp-punch/pp-core)

Installing PyEnv and Python

Link to the official pyenv documentation.

Linux

sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
source ~/.bashrc
pyenv install 3.6.8
pyenv global 3.6.8
source ~/.bashrc

Now, you should get the following output when using these commands:

python --version
Python 3.6.8

python3 --version
Python 3.6.8

Then install virtualenv for pyenv :

git clone https://github.com/pyenv/pyenv-virtualenv.git $PYENV_ROOT/plugins/pyenv-virtualenv
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile
# restart your shell
exec "$SHELL"

MacOS

xcode-select --install
brew install openssl readline sqlite3 xz zlib
# When running Mojave or higher (10.14+) you will also need to install the additional SDK headers(https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes#3035624):
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
source ~/.bash_profile
pyenv install 3.6.8
pyenv global 2.7.16 3.6.8
source ~/.bash_profile

In case installation of Python is failing:

sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install

Updating Pip and Wheel

List outdated packages:

pip list --outdated

Package    Version Latest Type 
---------- ------- ------ -----
pip        18.1    20.0.2 wheel
setuptools 40.6.2  45.2.0 wheel
You are using pip version 18.1, however version 20.0.2 is available.

Update pip, setuptools and install wheel before continuing to install punch requirements.

pip install --upgrade pip
pip install --upgrade setuptool
pip install --upgrade wheel