Hi, I install this package. But when I run the project I get a runtime error . I have a Anaconda Python 3.5.2 64 bits install. I use the Nuget PAckage 3.5. I have tried to run it with x86, Any CPU, amd x64. Any suggestions?
Now I'm running x86. Crash in this line Py.GIL().
There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "Python.Runtime, Version=2.3.0.0, Culture=neutral, processorArchitecture=x86", "x86". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project. PythonNet2
Windows 10
I installed it using the "MAnage Nuget Package" option in Visual Studio 2005.
I changed the "Target Platform Option" in project settings to x86. But I still get this runtime error in the same line:
An unhandled exception of type 'System.BadImageFormatException' occurred in Python.Runtime.dll
Additional information: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
@mphielipp are you really using VS 2005??? Your anaconda is clearly 64-bit, hence you need to select x64 target in VS. Which nuget pythonnet package did you install? There are many versions of them.
@denfromufa looks like you arrived to the same solution we did. We got it fixed by manually updating the dll reference to the 64bit version. I don't know how other libraries deal w this though, dllexport and nunit may have some solution for this.
@denfromufa i would like to confirm my understanding on this issue.
Do you mean that currently, the System.BadImageFormatException error still have not been solve if we downloaded Pythonnet from NuGet ?
I don't think this is something we can easily solve in code. We could, however, provide different NuGet packages for all relevant arch/python version combinations.
@filmor , no, it would not. Python versions issue, IMHO, should either be solved by having separate NuGet package names per python version (e.g pythonnet36 instead of pythonnet), or by having all versions in a single package.
Activity
den-run-ai commented on May 25, 2017
@mphielipp are you really using VS 2005??? Your anaconda is clearly 64-bit, hence you need to select x64 target in VS. Which nuget pythonnet package did you install? There are many versions of them.
What .NET runtime are you targetting?
What do these commands show?
where python
python --version
mphielipp commented on May 25, 2017
VS 2015
C:\Users<ny user>\AppData\Local\Continuum\Anaconda3\python.exe
Python 3.5.2 :: Anaconda 4.3.1 (64-bit)
mphielipp commented on May 25, 2017
.NET Framework 4.5.2
mphielipp commented on May 25, 2017
pythonnet_py35_dotnet 2.3.0
den-run-ai commented on May 25, 2017
I see the issue, nuget does not switch automatically the version of package (x86 and x64) depending on the architecture:
https://stackoverflow.com/questions/7769580/how-should-i-create-or-upload-a-32-bit-and-64-bit-nuget-package
vmuriart commented on May 25, 2017
@denfromufa looks like you arrived to the same solution we did. We got it fixed by manually updating the dll reference to the 64bit version. I don't know how other libraries deal w this though, dllexport and nunit may have some solution for this.
STREETKILLER007 commented on Aug 14, 2018
@denfromufa i would like to confirm my understanding on this issue.
Do you mean that currently, the System.BadImageFormatException error still have not been solve if we downloaded Pythonnet from NuGet ?
den-run-ai commented on Aug 14, 2018
filmor commented on Aug 30, 2018
I don't think this is something we can easily solve in code. We could, however, provide different NuGet packages for all relevant arch/python version combinations.
lostmsu commented on Dec 2, 2018
@filmor this should be possible with the new .NET Core nuget packages. They even support different target platforms.
filmor commented on Dec 2, 2018
That would still not solve the issue of different Python versions, would it?
lostmsu commented on Dec 3, 2018
@filmor , no, it would not. Python versions issue, IMHO, should either be solved by having separate NuGet package names per python version (e.g pythonnet36 instead of pythonnet), or by having all versions in a single package.
den-run-ai commented on Dec 3, 2018
@lostmsu can you provide references for the new nuget package specs of platform definitions?
lostmsu commented on Dec 3, 2018
@denfromufa , I can't find a tutorial, but this is what I am talking about: https://docs.microsoft.com/en-us/dotnet/core/rid-catalog
den-run-ai commented on Dec 3, 2018
lostmsu commented on Sep 24, 2021
This has been solved with the introduction of clr_loader for Python and Runtime.PythonDLL for .NET side.