Search code examples
pythonpyenvpython-3.6

Install Python of specific version system-wide with pyenv


I am researching possibility to upgrade to Python 3.6 in our project.

Right now we are using Python 3.5.2 from ppa:fkrull/deadsnakes on Ubuntu 14.04. The PPA doesn't have Python 3.6 yet and it's not clear when it will be available.

I don't want to install yet another PPA.

And I am trying to find a more general approach.

I found people suggesting to use pyenv which compiles Python from source, which sounds interesting, because I can upgrade Python any time without waiting until repo maintainer adds it. Also I can easily install other Python flavors like PyPy.

I am not ready to use pyenv as virtual environment yes, so I am wondering if it's possible to use it to compile and install Python globally so that I can just use it.


Solution

  • The documentation is a little confusing because there is no python-build binary added in PATH after installation.

    python-build is a pyenv plugin (installed by default). Documentation and more info is here: https://github.com/pyenv/pyenv/tree/master/plugins/python-build.

    How to install system-wide Python for all users: 1) Login as root and 2) install required Python version to /usr/local/python-X.Y.Z.

    sudo ~/.pyenv/plugins/python-build/bin/python-build 3.6.1 /usr/local/python-3.6.1/
    

    Now you can use this Python version as a normal user, for example you can create virtualenv for your project:

    /usr/local/python-3.6.1/bin/python -m venv /var/www/my-app/.env/