Install and Setup of PyEnv

PyEnv can be installed by downloading from here or if using a mac use brew install pyenv

If downloading from github do the following

git clone ~/.pyenv
cd ~/.pyenv && src/configure && make -C src

If using homebrew this will be installed into your homebrew path.

Setting Paths

To get pyenv to work we need to add the bin directory to our PATH. This can be dome by add the following into the ~/.profile

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

And this in your .bashrc

eval "$(pyenv init --path)"

Checking Versions

To see what versions of python are installed we can use

pyenv versions
* system (set by /home/jmacey/.pyenv/version)

This show the current installed version of python is the system one, we can confirm this by running

python -V
Python 2.7.5

As this is EOL we really need to update and install a better version. The current recommended vfx reference platform version is 3.9.x so lets see what versions we have.

pyenv install --list

Will list all of the version you will see that there are quite a few, lets filter the list a little with grep

pyenv install --list | grep " 3\.[9]"

This gives use a better list, we are going to install the final 3. 9version which is 3.9.7

We can now install using

pyenv install 3.9.7

If we now run

pyenv versions

We can see which versions of python are installed.

Global vs Local

PyEnv allows us to override any system installed python versions by using the version installed in a directory called .pyenv/shims/ these can be made permanent for the users session by using the ```pyenv global`` command.

pyenv global 3.9.7
python -V

It is also possible to setup a per directory local python version by using the pyenv local command. For example

mkdir pytmp
cd pytmp
pyenv local system
python -V

This will work for subfolders and can also be overridden on a per folder basis which is ideal for testing.


On my mac (M1) I had a few issues, whilst things installed ok when using python 3.7.12 I could not pass all the tests from python -m test there were some failures. However the main issues was when trying to import ctypes which failed with an import error.

 import ctypes
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/jmacey/.pyenv/versions/3.7.12/lib/python3.7/ctypes/", line 7, in <module>
    from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'

This seems to be an issue with python 3.7 on pyenv. If I test 3.9.x it all works fine as this is supported by Renderman my main python usage I will just use this.

More Reading

This article has some in depth information about how pyenv works