Keep Sharp

Configuration of Multiple Python Versions Using Pyenv

Installation of Pyenv:

$ git clone https://github.com/yyuu/pyenv.git ~/.pyenv

Add this to .bashrc file

#Add for pyenv
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

To check the available python version for installation, run pyenv install -l. I stalled python3.3.2 using pyenv install 3.3.2, using pyenv versions can get the installed python versions:

$ pyenv versions
* system
  3.3.2

In "~/.pyenv/" folder, the default 2.7.3 version is linked by "shims/", while 3.3.2 version is installed in "versions/" folder. Run ~/.pyenv/versions/3.3.2/bin/pip install PACKAGENAME will automatically install packages for python3 and put the libs in folder ~/.pyenv/versions/3.3.2/lib/python3.3/site-packages/, by this way of local installation, it won't mess up system's default python relevant packages. You can check the installed packages for each version by running ~/.pyenv/versions/3.3.2/bin/pip freeze and pip freeze.

There are 3 ways of switch to 3.3.2 version:

$ pyenv global 3.3.2 # set global python version
$ pyenv local 3.3.2  # set local python version for current folder
$ pyenv shell 3.3.2  # set python version for current shell session

the 2nd way is highly recommended, when you enter the folder whose local python version is set to be python3, when type python, it will automatically run python3, when cd out of the folder and type python, it will automatically switch back to system's default python2, it's amazing. This way we can run notebook for ipython3 in that folder.

Comments