VirtualPhotonics / Vts.Scripting.Python

Jupyter notebooks to call the VTS using Python
Other
0 stars 1 forks source link

nuget installed vts fails in Jupyter notebook #6

Open scottprahl opened 5 months ago

scottprahl commented 5 months ago

Not sure what is going on. I installed vts using nuget

mkdir vts
cd vts
nuget install VirtualPhotonics.Vts

Then executed the following in a JupyterLab notebook

import os
import clr
import numpy as np
import matplotlib.pyplot as plt
from System.Diagnostics import FileVersionInfo

# Vts version installed using Nuget currently fails when the next cell is executed
nuget_dll = "/Users/prahl/vts/VirtualPhotonics.Vts.10.0.0/lib/net6.0/Vts.dll"
git_dll = "/Users/prahl/Documents/Code/git/vts/publish/local/Vts.dll"

print("stats for:", git_dll)
print("file size is ", os.path.getsize(git_dll))
print(FileVersionInfo.GetVersionInfo(git_dll))

print("stats for:", nuget_dll)
print("file size is ", os.path.getsize(nuget_dll))
print(FileVersionInfo.GetVersionInfo(nuget_dll))

Which shows identical versions, but different file sizes for the two dlls

file size is  10562560
File:             /Users/prahl/Documents/Code/git/vts/publish/local/Vts.dll
InternalName:     Vts.dll
OriginalFilename: Vts.dll
FileVersion:      10.0.0.0
FileDescription:  Vts
Product:          Vts
ProductVersion:   10.0.0
Debug:            False
Patched:          False
PreRelease:       False
PrivateBuild:     False
SpecialBuild:     False
Language:         Language Neutral

stats for: /Users/prahl/vts/VirtualPhotonics.Vts.10.0.0/lib/net6.0/Vts.dll
file size is  10601984
File:             /Users/prahl/vts/VirtualPhotonics.Vts.10.0.0/lib/net6.0/Vts.dll
InternalName:     Vts.dll
OriginalFilename: Vts.dll
FileVersion:      10.0.0.0
FileDescription:  Vts
Product:          Vts
ProductVersion:   10.0.0
Debug:            False
Patched:          False
PreRelease:       False
PrivateBuild:     False
SpecialBuild:     False
Language:         Language Neutral

if I follow the above code with

clr.AddReference(git_dll)
from Vts import *

then everything is fine. If I restart the kernel and then do

clr.AddReference(nuget_dll) 
from Vts import *

it fails with

ModuleNotFoundError: No module named 'Vts'
lmalenfant commented 5 months ago

I had this same issue, when you pull a reference from NuGet, it only has the Vts.dll, the other dependent dlls need to be in the same folder otherwise it cannot resolve them. How NuGet works is that the other dependencies are also in their own folders, they would need to be grouped into a single location for this to work.

scottprahl commented 5 months ago

Oh I see.

The .dlls could readily extracted and copied to the parent directory with something like

cd vts
find . -name "*.dll" | xargs -I {} cp {} .

but this will require some nuget packaging work. Currently nuget installs dlls for all the target frameworks so who knows which framework version will be the last one copied. I will submit a patch that attempts to include only a single framework

scottprahl commented 5 months ago

Sorry, I have no idea how to help here. I thought I had an idea, but I was wrong :-(

scottprahl commented 5 months ago

You are also right about the just moving the dlls from the subdirectories to the parent folder. Once I did that, the nuget install version worked.

Unfortunately, I think that cloning the git repo, building, and then using "vts/publish/local/Vts.dll" is the easiest thing to ask people to do. Alternatively, you could just zip all the required dll files together and publish these with each release.

lmalenfant commented 5 months ago

Thank you for looking into it, I appreciate it!

I did think about creating a zip with the dlls although we kind of already have that with the MCCL release, that zip file will contain all the necessary dlls. I was wondering if we could leverage that here.

lmalenfant commented 4 months ago

@dcuccia I'm glad you are making progress, could you put your updates for using NuGet with Python in this issue?

lmalenfant commented 4 months ago

@dcuccia I just wanted to reach out and see how your progress is going on bringing the libraries into the Notebook using NuGet. We need to create a VTS release and if this is not a feasible solution we will need to have the zip file with the libraries.

Thank you!

dcuccia commented 4 months ago

Hi Lisa,

I've been at a conference all week, so no new updates from me just yet. I came up with a solution to use a local .csproj to bring in Vts.dll and it's dependencies, which worked well and decently elegantly. Might have been running into the same thing Scott did, however, which was that the library imported might have been incomplete. Needed to spend more time on that, but if that checks out, that might reveal a problem with how we are packaging our library for Nuget.

David