Skip to content

Commit 1eeeed8

Browse files
authored
Instructions to get python notebooks working on a Mac
1 parent c20c0c3 commit 1eeeed8

1 file changed

Lines changed: 126 additions & 1 deletion

File tree

README.md

Lines changed: 126 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,126 @@
1-
Jupyter notebooks to call the VTS using Python
1+
# Jupyter notebooks to call the VTS using Python
2+
3+
This is likely to change once `python` scripting is formally supported by `VTS`.
4+
5+
## Getting things working on a Mac
6+
7+
I did not have a .NET installation and do most things from the command line. This is a record of how I got `vts` working in `JupyterLab`.
8+
9+
### Step 1: Install .NET 6
10+
11+
You will need version 6 of .NET which is available from Microsoft below
12+
13+
https://dotnet.microsoft.com/en-us/download/dotnet/6.0
14+
15+
I saved everything to `$HOME/Documents/Code/dotnet6`
16+
17+
Do not forget to update your `.bash_profile` or whatever you use so that this directory is in your path. Also define `DOTNET_ROOT`
18+
19+
PATH=$PATH:$HOME/Documents/Code/dotnet6
20+
21+
export DOTNET_ROOT=$HOME/Documents/Code/dotnet6
22+
23+
### Step 2: Install VTS
24+
25+
Follow the guidelines at https://github.com/VirtualPhotonics/VTS/wiki/Getting-Started-on-Mac Briefly, clone the `.git` repo
26+
27+
git clone https://github.com/VirtualPhotonics/vts.git
28+
29+
This will create the director `vts` that we will use in the next step
30+
31+
When you are using `brew` you might as well install `nuget` at the same time
32+
33+
brew install powershell
34+
brew install nuget
35+
36+
Now build VTS. If you don't have `matlab` don't worry, it seemed to work fine without completing the `matlab` tests
37+
38+
pwsh
39+
cd vts
40+
./BuildTestRelease.ps1
41+
exit
42+
43+
### Step 3: Install .NET dlls
44+
45+
Navigate to the release version of vts.dll
46+
47+
cd vts/src/Vts/bin/Release/net6.0
48+
49+
Now use `nuget` to install the extra required libraries
50+
51+
nuget install MathNet.Numerics.dll
52+
nuget install Newtonsoft.Json.dll
53+
nuget install Nlog.dll
54+
nuget install System.Reactive.dll
55+
56+
rummage through all the folders and move the net6.0 `*.dll` to `vts/src/Vts/bin/Release/net6.0` . Doing `ls` in this directory should show
57+
58+
MathNet.Numerics.dll
59+
Newtonsoft.Json.dll
60+
Nlog.dll
61+
System.Reactive.dll
62+
Vts.dll
63+
64+
### Step 4: Install pythonnet
65+
66+
pip install pythonnet
67+
68+
Now because `pythonnet` assumes that you're using `mono` and not `.NET`, we need to update a few more things in .bash_profile
69+
70+
export PYTHONNET_RUNTIME=coreclr
71+
export PYTHONNET_PYDLL=/usr/local/bin/python3
72+
73+
Change the path for python to that for your system (try `which python3` if you don't know)
74+
75+
Start a `JupyterLab` notebook and verify that things are installed correctly
76+
77+
import clr
78+
79+
clr.AddReference("System")
80+
from System import Console
81+
Console.WriteLine("Hello from .NET 6!")
82+
83+
Once this works the next step will be to add the `Vts.dll`
84+
85+
import sys
86+
87+
dll_directory = "/path/to/vts/src/Vts/bin/Release/net6.0"
88+
sys.path.append(dll_directory)
89+
clr.AddReference("Vts")
90+
91+
Once this is working, verify that the other dlls you downloaded load properly
92+
93+
clr.AddReference("Newtonsoft.Json")
94+
clr.AddReference("Mathnet.Numerics")
95+
clr.AddReference("NLog")
96+
clr.AddReference("System.Reactive");
97+
98+
And now you should be able to run `VTS` programs in `python` with the header
99+
100+
import sys
101+
dll_directory = "/path/to/vts/src/Vts/bin/Release/net6.0"
102+
sys.path.append(dll_directory)
103+
104+
import clr
105+
clr.AddReference("Vts")
106+
clr.AddReference("Newtonsoft.Json")
107+
clr.AddReference("Mathnet.Numerics")
108+
clr.AddReference("NLog")
109+
clr.AddReference("System.Reactive")
110+
111+
from Vts import *
112+
from Vts.Common import *
113+
from Vts.Extensions import *
114+
from Vts.Modeling.Optimizers import *
115+
from Vts.Modeling.ForwardSolvers import *
116+
from Vts.Factories import *
117+
from Vts.MonteCarlo import *
118+
from Vts.MonteCarlo.Sources import *
119+
from Vts.MonteCarlo.Tissues import *
120+
from Vts.MonteCarlo.Detectors import *
121+
from Vts.MonteCarlo.Factories import *
122+
from Vts.MonteCarlo.PhotonData import *
123+
from Vts.MonteCarlo.PostProcessing import *
124+
from System import Array, Double
125+
126+

0 commit comments

Comments
 (0)