Skip to main content

Python Dependencies

Declare Python dependencies next to the script with PEP 723 metadata. RevitDevTool reads that metadata, prepares the supported Python environment, and then runs the script with its dependencies available.

Inline metadata​

# /// script
# dependencies = [
# "polars==1.38.1",
# "numpy==2.4.2",
# "openpyxl==3.1.5",
# ]
# ///

The metadata is part of the script, so it can be committed, reviewed, and reproduced without a separate environment file.

Package sources​

Host pathPrimary sourceFallback or exception
Revit and most AutoCAD-family hostsPixi with conda-forge and PyPIpip or pyRevit cengines
Plant 3Duv sidecar environmentpip matching the host Python minor version

Plant 3D is different because it embeds CPython before RevitDevTool loads. RevitDevTool attaches to that interpreter and uses a uv sidecar; it does not start a second in-process interpreter.

For runtime selection and host differences, see Python Ecosystems For Revit.

Versioning guidance​

  • Pin versions for production scripts and examples.
  • Use compatible versions for the Python runtime and host architecture.
  • Prefer packages with wheels available for the target Python version.
  • Keep dependency declarations small; remove unused packages.
  • Treat package upgrades as code changes and test against the target Autodesk host.

Unpinned ranges are useful while exploring, but can produce different results when the package index changes.

Common workflows​

Data analysis​

Use packages such as Polars, NumPy, and OpenPyXL for model extraction, analysis, and reporting:

# /// script
# dependencies = ["polars", "openpyxl"]
# ///

import polars as pl

Geometry and research​

Add computational-geometry or scientific packages when the workflow needs them, then keep Revit API interaction at the boundary of the script. This makes package failures easier to separate from host API failures.

Debugging dependency code​

Prepare dependencies before starting the debugger. For CPython breakpoints, attach VS Code to the debugpy port shown by RevitDevTool, then run the script. See Attach Debugger.

Troubleshooting​

SymptomCheck
A package cannot be resolvedCheck the package name, version, network access, and whether a wheel exists for the target Python version
Import fails after a successful installConfirm the import name differs from the distribution name and that the script uses the prepared environment
Plant 3D installation behaves differentlyUse the uv sidecar path; Plant 3D does not use the Pixi-owned interpreter path
A package conflicts with host behaviorTry a compatible version and avoid packages that replace assemblies or native libraries already loaded by the host
Debugger cannot import the packagePrepare dependencies first, then attach to the active CPython debug port