Python - pyenv notes

Use pyenv

pyenv commands

# list all available pyenv commands
pyenv commands

pyenv local

# set local python version (3.7.0)
pyenv local 3.7.0

# set multiple local python versions (prefer 3.7.0 over 3.7.3)
pyenv local 3.7.0 3.7.3

# set multiple local python versions (prefer 3.7.3 over 3.7.0)
pyenv local 3.7.3 3.7.0

# unset the local python version
pyenv local --unset

pyenv global

# set global python version (3.7.3)
pyenv global 3.7.3

# set multiple global python versions (prefer 3.7.0 over 3.7.3)
pyenv global 3.7.0 3.7.3

# set multiple global python versions (prefer 3.7.3 over 3.7.0)
pyenv global 3.7.3 3.7.0

pyenv shell

# set system python as the shell python version
pyenv shell system

# unset the shell python version
pyenv shell --unset

pyenv versions

# list all python versions available to pyenv
pyenv versions

pyenv version

# show the current python version and its origin
pyenv version

pyenv install

# list all available python versions
pyenv install -l

# install python 2.7.15
pyenv install 2.7.15

# install python 3.7.0
pyenv install 3.7.0

# install activepython-3.6.0
pyenv install activepython-3.6.0

# install anaconda3-5.2.0
pyenv install anaconda3-5.2.0

# install ironpython-2.7.7
pyenv install ironpython-2.7.7

# install jython-2.7.1
pyenv install jython-2.7.1

# install micropython-1.9.4
pyenv install micropython-1.9.4

# install miniconda3-4.3.30
pyenv install miniconda3-4.3.30

# install pypy3.5-6.0.0
pyenv install pypy3.5-6.0.0

# install pyston-0.6.1
pyenv install pyston-0.6.1

# install stackless-3.5.4
pyenv install stackless-3.5.4

pyenv uninstall

# uninstall python 2.7.15
pyenv uninstall 2.7.15

# uninstall python 3.7.0
pyenv uninstall 3.7.0

pyenv rehash

Note: run this command after installing a new version of Python

# install shims for all python binaries known to pyenv
pyenv rehash

Use pyenv-virtualenv

# create virtualenv called 'venv-2.7.15' using Python 2.7.15
pyenv virtualenv 2.7.15 venv-2.7.15

# create virtualenv called 'venv37' using current Python version
pyenv virtualenv venv37

# list existing virtualenvs
pyenv virtualenvs

# manually activate virtualenv called 'venv37'
pyenv activate venv37

# manually deactivate virtualenv called 'venv37'
pyenv deactivate venv37

# delete existing virtualenv called 'venv37'
pyenv uninstall venv37

Using Python 3

# start python 3
python3

# get python 3 version
python3 --version

# show location of python 3
which python3

# get python 3 pip version
python3 -m pip --version
pip3 --version

# list installed python 3 packages
python3 -m pip list
pip3 list

# install python 3 packages
python3 -m pip install virtualenv numpy matplotlib
pip3 install virtualenv numpy matplotlib

# upgrade python 3 packages
python3 -m pip install --upgrade pip setuptools wheel
pip3 install --upgrade pip setuptools wheel

# uninstall python 3 packages
python3 -m pip uninstall virtualenv numpy matplotlib
pip3 uninstall virtualenv numpy matplotlib

# create virtualenv with venv (Python 3.3+)
python3 -m venv path-to-venv

# create virtual environment with virtualenv (Python 3.3+)
python3 -m virtualenv path-to-venv
virtualenv path-to-venv

# activate virtual environment
source path-to-venv/bin/activate

# freeze packages (venv)
# freeze system and local packages (virtualenv)
pip freeze > requirements.txt

# freeze local packages (virtualenv)
pip freeze -l > requirements.txt

# install required packages
pip install -r requirements.txt

# deactivate virtual environment
deactivate

Using Python 2

# start python 2
python2

# get python 2 version
python2 --version

# show location of python 2
which python2

# get python 2 pip version
python2 -m pip --version
pip2 --version

# list installed python 2 packages
python2 -m pip list
pip2 list

# install python 2 packages
python2 -m pip install virtualenv numpy matplotlib
pip2 install virtualenv numpy matplotlib

# upgrade python 2 packages
python2 -m pip install --upgrade pip setuptools wheel
pip2 install --upgrade pip setuptools wheel

# uninstall python 2 packages
python2 -m pip uninstall virtualenv numpy matplotlib
pip2 uninstall virtualenv numpy matplotlib

# create virtual environment with virtualenv (Python 2.6+)
python2 -m virtualenv path-to-venv
virtualenv path-to-venv

# activate virtual environment
source path-to-venv/bin/activate

# freeze packages (venv)
# freeze system and local packages (virtualenv)
pip freeze > requirements.txt

# freeze local packages (virtualenv)
pip freeze -l > requirements.txt

# install required packages
pip install -r requirements.txt

# deactivate virtual environment
deactivate

© 2020 | Paul Kim