Versioned Python scripts

State the BornAgain version and package requirements in each script, and run it in an environment that satisfies those requirements.

Runtime guard

Scripts shipped with BornAgain check the installed version right after the import:

import bornagain as ba
ba.require_versions("bornagain>=25,<26")

ba.require_versions accepts any number of PEP 508 requirement strings, e.g. "bornagain>=25,<26", "python>=3.10", "numpy>=1.21.2". If a script needs additional packages, add these requirements explicitly. For example:

import bornagain as ba
ba.require_versions(
    "bornagain>=25,<26",
    "python>=3.10",
    "numpy>=1.21.2",
    "scipy>=1.7.2",
    "lmfit==1.3.4",
    "fabio",
)

If a requirement is not met, the script stops immediately with an ImportError that names the installed and the required version. Use the same guard in your own scripts.

Run in a virtual environment

Follow the installation instructions for your platform. Install any additional packages required by the script in the same environment. With that environment activated, run:

python my_script.py

Run with uv

Scripts shipped with BornAgain also declare their requirements in a PEP 723 comment block:

# /// script
# requires-python = ">=3.10"
# dependencies = ["bornagain>=25,<26"]
# ///

Include any extra packages needed by your script in dependencies too.

On Linux and Windows, uv installs these dependencies in an isolated environment for the script:

uv run my_script.py

Use a supported Python version. To select one explicitly:

uv run --python 3.14.5 my_script.py