Python Package Management
TLDR
- Use uv instead of conda and pip if possible
- uv takes up less space and is much friendlier to the cluster's processes, which makes your jobs run smoother
Using uv Instead of pip
Whenever possible, we recommend managing a python environment via uv rather than pip or conda. With that said, there are some packages that only conda environments can handle, in which case you should use it instead.
Creating a new project with uv
-
Load uv
-
Initialize the project by running
replacing<project name>with the name of your project. This will create git files, package toml and lock files, as well as a template main.py file. Alternatively, if you don't want the unnecessary files, run which will just generate the toml file. Treat this file like requirements.txt. -
Install packages by running
which will automatically add to the toml file. If you need to install from a specific link (i.e., setting --index-from-url with pip installs), add the--index <index>flag replacing<index>with your link.
Creating or Managing Pre-existing venvs
For compatibility, uv also supports python generated venvs.
To create a new venv, run:
replacing<venv name?> with the name of your venv. This is optional- the default venv name is .venv
Once you have a venv, whether you made it with pip or uv, simply running uv pip install <package> will add it to your venv, even without you activating it.
For more help with uv, look into the official docs for more information.
Specifying Python Versions
You can optionally add --python <version> to the uv init or uv venv command to install a specific version that meets your needs.
Installing from File
when using uv pip install, both requirements.txt and pyproject.toml can work, but uv may throw errors when using requirements.txt, such as when you install from a specific url. In these cases, install the links line by line, then install the rest.