# Python Support ```eval_rst .. toctree:: :glob: :maxdepth: 3 ``` [OmniTrace](https://github.com/ROCm/omnitrace) supports profiling Python code at the source-level and/or the script-level. Python support is enabled via the `OMNITRACE_USE_PYTHON` and the `OMNITRACE_PYTHON_VERSIONS=".` CMake options. Alternatively, to build multiple python versions, use `OMNITRACE_PYTHON_VERSIONS=".;[.]"`, and `OMNITRACE_PYTHON_ROOT_DIRS="/path/to/version;[/path/to/version]"` instead of `OMNITRACE_PYTHON_VERSION`. When building multiple Python versions, the length of the `OMNITRACE_PYTHON_VERSIONS` and `OMNITRACE_PYTHON_ROOT_DIRS` lists must be the same size. > ***When using omnitrace for Python, the Python interpreter major and minor version (e.g. 3.7) must match the interpreter major and minor version*** > ***used when compiling the Python bindings, i.e. when building omnitrace, a `libpyomnitrace.----.so` will be generated*** > ***where `IMPL` is the Python implementation, `VERSION` is the major and minor version, `ARCH` is the architecture,*** > ***`OS` is the operating system, and `ABI` is the application binary interface; Example: `libpyomnitrace.cpython-38-x86_64-linux-gnu.so`.*** ## Getting Started The omnitrace Python package is installed in `lib/pythonX.Y/site-packages/omnitrace`. In order to ensure the Python interpreter can find the omnitrace package, add this path to the `PYTHONPATH` environment variable, e.g.: ```bash export PYTHONPATH=/opt/omnitrace/lib/python3.8/site-packages:${PYTHONPATH} ``` If using either the `share/omnitrace/setup-env.sh` script or the modulefile in `share/modulefiles/omnitrace`, prefixing the `PYTHONPATH` environment variable is automatically handled. ## Running OmniTrace on a Python Script OmniTrace provides an `omnitrace-python` helper bash script which effectively handles ensuring `PYTHONPATH` is properly set and the correct python interpreter is used. Thus the following are effectively equivalent: ```bash omnitrace-python --help export PYTHONPATH=/opt/omnitrace/lib/python3.8/site-packages:${PYTHONPATH} python3.8 -m omnitrace --help ``` > ***`omnitrace-python` / `python -m omnitrace` uses the same command-line syntax as the `omnitrace` executable (i.e. `omnitrace-python --