Skip to content

Getting Started with Command‐Line

Carole Hayakawa edited this page Mar 3, 2026 · 12 revisions

Using VTS with Python Scripts

This information will likely change as more support for python and .NET is introduced.
Note: please use python version 3.13 because 3.14 does not have pythonnet support yet.

Installation details

Step 1: Install .NET 10

You will need version 10 of .NET which is available from Microsoft below

https://dotnet.microsoft.com/en-us/download/dotnet/10.0

On Ubuntu Linux:

Do not forget to update your ~/.bashrc or whatever you use so that this directory is in your path. Also define DOTNET_ROOT

export DOTNET_ROOT=/usr/share/dotnet
PATH=$PATH:$DOTNET_ROOT

Install pip

sudo apt install python3-pip

Step 2: Clone the scripting repository

git clone https://github.com/VirtualPhotonics/vts.git

Step 3: Download the VTS libraries

Get the latest VTS libraries for the specific platform from releases and extract them into the libraries folder under Vts.Scripting.Python.

Step 4: Install pythonnet, numpy, plotly, scipy (list may grow as we add examples)

pip install pythonnet
pip install numpy
pip install plotly
pip install scipy
pip install matplotlib

Note for MacOS and Linux: Because pythonnet under macOS (or linux) defaults to mono, two more things need to added to ~/.bashrc

export PYTHONNET_RUNTIME=coreclr
export PYTHONNET_PYDLL=/usr/local/bin/python3 (MacOS)
export PYTHONNET_PYDLL=/usr/bin/python3 (Linux)

Use the path for python on your system (which python3 will tell you)

Step 5: Run programs

To run .py scripts in this repository change directory to folder and run script

cd forward-solvers
python r-of-rho.py

These commands can be run on Linux or on Windows within a PowerShell window.

To create new scripts that access the VTS library include the following the header

    from pythonnet import load
    load('coreclr')
    import clr
    import os
    file = '../libraries/Vts.dll'
    clr.AddReference(os.path.abspath(file))
    import numpy as np  
    import plotly.graph_objects as go  
    from Vts import *
    from Vts.Common import *
    from Vts.Extensions import *
    from Vts.Modeling.Optimizers import *
    from Vts.Modeling.ForwardSolvers import *
    from Vts.SpectralMapping import *
    from Vts.Factories import *
    from Vts.MonteCarlo import *
    from Vts.MonteCarlo.Sources import *
    from Vts.MonteCarlo.Tissues import *
    from Vts.MonteCarlo.Detectors import *
    from Vts.MonteCarlo.Factories import *
    from Vts.MonteCarlo.PhotonData import *
    from Vts.MonteCarlo.PostProcessing import *
    from System import Array, Object