Skip to content

Installing pysmo

Requirements

Pysmo needs a few packages from PyPI (NumPy, SciPy, and others), all installed automatically. It runs on Python 3.13 and 3.14 on Linux, macOS, and Windows.

Installing packages by hand is fiddly. It means creating a virtual environment, activating it, and running pip install for each package. It is also easy to lose track of what is installed.

Software-development tools automate this. That helps anyone running Python, not only developers. uv creates the environment, installs Python when needed, and records each package added.

Create a project and add pysmo, plus mypy for the next chapter:

uv init my-analysis
cd my-analysis
uv add pysmo
uv add --dev mypy  # tooling, separate from the code's dependencies

uv add records pysmo in pyproject.toml. It also pins the full dependency tree in uv.lock. From those two files the environment can be rebuilt exactly, later or on another machine. Commit both.

Run code with uv:

uv run my_script.py
uv run mypy my_script.py

Elsewhere, uv sync restores the environment from those two files.

Drop the uv run prefix

direnv can activate the project environment on entering the directory, so python, mypy, and other tools run directly. Create .envrc:

watch_file pyproject.toml uv.lock
uv sync --quiet
source .venv/bin/activate

Then run direnv allow. The environment now tracks pyproject.toml and uv.lock automatically.

A single script

For a one-off analysis, uv can attach dependencies to a single file instead of a project directory. They go in a metadata block at the top of the script.

uv init --script analysis.py
uv add --script analysis.py pysmo
uv run analysis.py

uv run installs the listed dependencies before running the script.

Type-checking a single-file script is less convenient: a script's inline dependencies are not visible to a separately-invoked type checker. For anything involving mypy, the project layout above is smoother.

Installing into an existing environment

To install pysmo into an environment managed another way (a virtual environment or a conda environment), activate it and use pip:

python3 -m pip install pysmo

Prefer a virtual environment over the system Python. It needs no administrator rights and keeps each project's dependencies separate.

Pre-release and development versions

The commands above install the latest stable release. For a pre-release or the development version from GitHub:

uv add pysmo --prerelease allow
uv add "pysmo @ git+https://github.com/pysmo/pysmo"
uv add --script analysis.py pysmo --prerelease allow
uv add --script analysis.py "pysmo @ git+https://github.com/pysmo/pysmo"
python3 -m pip install pysmo --pre
python3 -m pip install "git+https://github.com/pysmo/pysmo"

Upgrading

uv sync --upgrade-package pysmo
uv sync --script analysis.py --upgrade-package pysmo
python3 -m pip install -U pysmo

Removing

uv remove pysmo
uv remove --script analysis.py pysmo
python3 -m pip uninstall pysmo

pip leaves automatically-installed dependencies behind. pip list shows what is installed. Remove anything unwanted with pip uninstall.