System.TypeLoadException: Could not load type 'Python.Runtime.PyLong' from assembly 'Python.Runtime, Version=3.0.1.0, Culture=neutral, PublicKeyToken=5000fea6cba702dd'.
dariusz-wozniak opened this issue ยท 5 comments
dariusz-wozniak commented
Using:
- Numpy.Bare Version="3.8.1.28"
- Numpy.Bare.Mono Version="3.8.1.28"
- PackageReference Version="3.0.1"
When initializing code in the Program.cs:
Runtime.PythonDLL = @"C:\Python311\python311.dll";
if (!PythonEngine.IsInitialized) PythonEngine.Initialize();
np.arange(1);
I get exception at the np.arange(1);
line:
System.TypeLoadException: Could not load type 'Python.Runtime.PyLong' from assembly 'Python.Runtime, Version=3.0.1.0, Culture=neutral, PublicKeyToken=5000fea6cba702dd'.
at Numpy.np.ToPython(Object obj)
at Numpy.np.ToTuple(Array input)
at Numpy.np.arange(Int32 stop, Int32 step, Dtype dtype)
at Sennheiser.Features.Linearization.PythonInitialization.Initialize() in
Any idea how to fix it?
henon commented
Does pylong work when you try directly with pythonnet v3.0.1?
dariusz-wozniak commented
Does pylong work when you try directly with pythonnet v3.0.1?
When I remove all Numpy.Bare.* packages from the solution then:
- The code works if I replace
np.arrange(1)
by:
using (Py.GIL())
{
dynamic np = Py.Import("numpy");
dynamic sin = np.sin;
var sin5 = sin(5);
}
- The code doesn't work if I replace
np.arrange(1)
by:
using (Py.GIL())
{
dynamic np = Py.Import("numpy");
dynamic arrange = np.arrange;
var a1 = arrange(1);
}
...Then I have an exception on dynamic arrange = np.arrange
:
System.Collections.Generic.KeyNotFoundException: The module has no attribute 'arrange'
at Python.Runtime.PyModule.Get(String name)
at Python.Runtime.PyModule.TryGetMember(GetMemberBinder binder, Object& result)
at CallSite.Target(Closure , CallSite , Object , Int32 , Int32 , Double , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecute5[T0,T1,T2,T3,T4,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
Also tried with the dynamic arrange = np.arrange(1);
but got the same exception.
henon commented
arange is with one r
henon commented
I already know what is your problem, I see it now above: you are using Numpy.Bare vor python3.8 with latest python3.11, of course that won't work
dariusz-wozniak commented
True. It solved the issue, thank you ๐