Lab 1 Python Setup

The aim of this lab is to setup our python environment in the lab and give you the ability to setup something similar at home.

We will cover:

  1. Installing a specific Python version globally and locally
  2. Creating a virtual environment
  3. Managing dependencies with pyproject.toml
  4. Running tests with pytest

Default Python Version

Why not use the default python version that comes with the OS?

RHEL comes shipped with python installed however they are quite old versions, in addition to this the system python is used by the OS and should not be changed.

They are also quite restricted in what you can install as a lot of the header files and core dependencies are not installed as they would clash with each other.

PyEnv

It is possible to use pyenv to manage my python environments. This allows me to have multiple versions of python installed on my machine and switch between them easily. Which can be useful when working with different software packages that require different versions of python as well as testing for the different DCC python versions.

In the last few years a new tool called UV has become more popular and I have now decided we should switch to this as it is more modern and has a few more features.

Installing UV

To install UV, run the following command in your terminal under linux (note it is installed in the lab already)

curl -LsSf https://astral.sh/uv/install.sh | sh

Alternatively, use Homebrew on macOS:

brew install astral-sh/uv/uv

If using windows at home you can use

powershell -c "irm https://astral.sh/uv/install.ps1 | iex"

This is going to install the uv command line tool into your home directory .local/bin/ uv.

Setting a Python Version

There are two ways to set a Python version with UV: globally and locally. I typically set one global version then per project I can set a local version if required. But what version to choose?

DCC Python version

In the labs at present we have the following version

ToolPython Versiontool name
Maya3.11.4mayapy
Houdini3.11.7hython
Nuke3.11.7python3
Renderman3.11.10rmanpy3

So which version to use? We are mainly using the vfx reference platform CY2026 because of out maya usage, so we should use python 3.13.x as our global version mainly due to the version of PySide / PyQt we are using and WebGPU / OpenGL. If we need to use the DCC tools we can add a lower version if needed.

Installing and Managing Python Versions

With uv, you can install and manage Python versions efficiently. To install a specific Python version, run:

uv python install 3.13

To list installed versions:

uv python list

To switch between installed Python versions:

uv python pin 3.13

To confirm the active Python version:

uv run python -V
Python 3.13.8

adding a different python

If you want to add a different version of python you can do this with the following command

uv python install 3.10

now we can test this by running

mkdir p10
cd p10
python -V 
3.11.11
uv python pin 3.10
python -V
3.10.11

You will notice a file called .python-version in the directory which is used to store the version of python for that directory.

Virtual Environments

A virtual environment is a self-contained directory that contains a Python installation for a particular version of Python, plus a number of additional packages. This allows you to have multiple projects on the same machine, each with its own dependencies.

The main issue with virtual environments is that they can be quite large and take up a lot of space on your hard drive. The advantage of using uv is that it uses a shared cache for all your virtual environments so you only have one copy of each package on your machine.

By default, uv uses global, shared environments for dependencies. This means:

  • Packages are not duplicated across virtual environments.
  • Different projects using the same package/version reference a single shared copy.
  • This significantly reduces disk space compared to traditional venvs.

A new project

The real power of uv is when you start a new project. You can create a new project with the following command

uv init PyProject 
cd PyProject
ls
hello.py  pyproject.toml  README.md

We can now run the hello.py file with the following command

uv run  hello.py
Hello, World!

Adding some tests

In the project we can add a directory called tests

mkdir tests
touch tests/test_add.py

In the test_add.py file we can add the following code

from hello import add

def test_add() :
    assert add(2,4) == 6

We can now use the uvx command to run the tests (this will install pytest if it is not already installed) we also need to add the following to the pyproject.toml file

dependencies = [
    "pytest"
    ]
uvx pytest

You will see the test fails as we have not written the add function yet.

def add(a,b) :
    return a+b

ruff

Ruff is a tool that can be used to check your code for PEP8 compliance. As well are formatting and other issues, this replaces various other tools such as flake8, black, isort etc.

uvx ruff check

On fist run this will install ruff and then run the check. We can also format the code with

uvx ruff format

Some useful commands

show where python is installed

uv python dir
/home/jmacey/.local/share/uv/python

show where any tools are installed

uv tool dir
/home/jmacey/.local/share/uv/tool
Next