Note: This is an archived version of the Blender Developer Wiki (archived 2024). The current developer documentation is available on developer.blender.org/docs.

User:Brita/Configs/Pyenv

pyenv - managing Python versions and dependencies

Pyenv is a tool that allows installing and managing several Python versions and environments for different projects with their own set of dependencies. This is useful when having multiple projects using python or to leave the Python system installation unchanged.

Pyenv copies Python versions, flavors and environments into a local folder which then can be selected from a directory using shims.

Read more.


Installing

See https://github.com/yyuu/pyenv-installer

$ curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash


Configuring

pyenv install 3.7.2  # installs a new python version (-l to list all possibilities first after pyenv update)
pyenv virtualenvs  # shows the list of existing virtualenvs
pyenv version  # shows the python version that will be applied to a newly created venv
pyenv virtualenv [2.7] venv-name  # creates new venv with optional specific version
pyenv local 3.7.2  # associate this folder with a version  without a virtualenv
pyenv local venv-name  # associates the new venv with the directory

Reference: https://github.com/yyuu/pyenv/blob/master/COMMANDS.md


Using Pyenv with Blender

  • Install the Python version that Blender currently requires and setup a virtual environment for it:
pyenv install 3.7.2
pyenv virtualenv 3.7.2 venv-blender
pyenv local venv-blender # run from the build directory
  • Install Blender's Python dependencies in the new virtual environment:
pip install requirements numpy requests
  • Set the path for the pyenv python directory before running CMake:

Blender's CMake configuration will fail if it does not find Python 3.7, so setting the path is useful if the OS doesn't have Python3.

export PYTHON_ROOT_DIR=$HOME/.pyenv/versions/3.7.2

This is an example for the final values, notice that the paths refer the venv for the installed packages, otherwise they refer the generic python version:

PYTHON_EXECUTABLE:FILEPATH=/home/stitch/.pyenv/versions/3.7.2/bin/python3.7
PYTHON_INCLUDE_CONFIG_DIR:PATH=/home/stitch/.pyenv/versions/3.67.2/include/python3.7m
PYTHON_INCLUDE_DIR:PATH=/home/stitch/.pyenv/versions/3.7.2/include/python3.7m
PYTHON_LIBPATH:PATH=/home/stitch/.pyenv/versions/3.7.2/lib
PYTHON_LIBRARY:FILEPATH=/home/stitch/.pyenv/versions/3.7.2/lib/libpython3.7m.a
PYTHON_LINKFLAGS:STRING=-Xlinker -export-dynamic
PYTHON_VERSION:STRING=3.7
PYTHON_NUMPY_PATH:PATH=/home/stitch/.pyenv/versions/venv-blender/lib64/python3.7/site-packages
PYTHON_NUMPY_INCLUDE_DIRS:PATH=/home/stitch/.pyenv/versions/venv-blender/lib64/python3.7/site-packages/numpy/core/include
PYTHON_REQUESTS_PATH:PATH=/home/stitch/.pyenv/versions/venv-blender/lib64/python3.7/site-packages
PYTHON_SITE_PACKAGES:FILEPATH=/home/stitch/.pyenv/versions/venv-blender/lib64/python3.7/site-packages


Updating

# check for new python versions and flavors
pyenv update
pyenv install -l  # list available versions
pyenv install 3.7.2
# update the default system versions
pyenv global 2.7 3.7
# update the Python version associated with the virtual environment for Blender
rm ~/.pyenv/versions/venv-blender
pyenv virtualenv 3.7.2 venv-blender
# check for outdated python pip dependencies:
pip list --outdated

# update all pip requirements:
pip freeze --local | grep -v '^\-e' | cut -d = -f 1  | xargs pip install -U