Matias Guijarro, matias.guijarro@free.fr
PUG Grenoble, 22/10/2015
Introduction
So many Pythons...
What if you need more than 1 Python ?
... here comes the need for a standalone Python versions manager
pyenv
Fork of rbenv by Yuu Yamashita
pyenv
pyenv lets you easily switch between multiple versions of Python
Just Unix shell scripts !
pyenv
How it works ?
Note: In computer programming, a shim is a small library that transparently intercepts API calls and changes the arguments passed, handles the operation itself, or redirects the operation elsewhere.
$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
# use pyenv first
$ echo $PATH
~/.pyenv/shims:~/.pyenv/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
pyenv
Choosing the Python version
pyenv
pyenv does not automatically create shims for
new executables after installation
pyenv installation
matias@kashyyyk:~$ git clone https://github.com/yyuu/pyenv.git ~/.pyenv
Cloning into '/home/matias/.pyenv'...
[...]
Checking connectivity... done.
matias@kashyyyk:~$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
matias@kashyyyk:~$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
matias@kashyyyk:~$
matias@kashyyyk:~$ echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
matias@kashyyyk:~$ source ~/.bash_profile
pyenv usage
matias@kashyyyk:~$ pyenv install 3.4.3
Downloading Python-3.4.3.tgz...
-> https://yyuu.github.io/pythons/4281ff86778db65892c05151d5de738d
Installing Python-3.4.3...
WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib?
Installed Python-3.4.3 to /home/matias/.pyenv/versions/3.4.3
matias@kashyyyk:~$ pyenv versions
* system (set by /home/matias/.pyenv/version)
3.4.3
matias@kashyyyk:~$
pyenv usage
matias@kashyyyk:~$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
matias@kashyyyk:~$ pyenv shell 3.4.3
matias@kashyyyk:~$ python
Python 3.4.3 (default, Oct 21 2015, 23:47:55)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
matias@kashyyyk:~$ which pip
/home/matias/.pyenv/shims/pip
matias@kashyyyk:~$
starting from here, installing a package with 'pip' would target Python 3.4.3, not messing anything with system Python
Useful links
An alternative: https://github.com/saghul/pythonz
pyenv plugins
The END
Questions ?