henon / Python.Included

A Python.NET based framework enabling .NET libraries to call into Python packages without depending on a local Python installation.
MIT License
313 stars 51 forks source link

Does not work on x86 #34

Closed rvetere closed 1 year ago

rvetere commented 2 years ago

I tried to override the DownloadUrl like i have seen in the examples:

Python.Deployment.Installer.Source = new Python.Deployment.Installer.DownloadInstallationSource()
{
    DownloadUrl = Environment.Is64BitProcess ? @"https://www.python.org/ftp/python/3.7.3/python-3.7.3-embed-amd64.zip" : @"https://www.python.org/ftp/python/3.7.3/python-3.7.3-embed-win32.zip",
};

As soon as i start the app with x86 Platform, i get an error telling me System.BadImageFormatException: "Could not load file or assembly 'Python.Runtime, Version=2.5.1.0, Culture=neutral, PublicKeyToken=null'.

I'm sure this is because somewhere the "amd64" image is hardcoded in Python.Included? But i don't know what would we need to update in the code of this package to make this work.

henon commented 2 years ago

Look at the examples which download and install a custom python distribution instead of using the embedded one.

henon commented 2 years ago

https://github.com/henon/Python.Included/blob/master/examples/Python.Deployment.Download/Program.cs

FrizzTheSnail commented 2 years ago

I tried to override the DownloadUrl like i have seen in the examples:

Python.Deployment.Installer.Source = new Python.Deployment.Installer.DownloadInstallationSource()
{
    DownloadUrl = Environment.Is64BitProcess ? @"https://www.python.org/ftp/python/3.7.3/python-3.7.3-embed-amd64.zip" : @"https://www.python.org/ftp/python/3.7.3/python-3.7.3-embed-win32.zip",
};

As soon as i start the app with x86 Platform, i get an error telling me System.BadImageFormatException: "Could not load file or assembly 'Python.Runtime, Version=2.5.1.0, Culture=neutral, PublicKeyToken=null'.

I'm sure this is because somewhere the "amd64" image is hardcoded in Python.Included? But i don't know what would we need to update in the code of this package to make this work.

Did you find a solution? I tried the same thing like you, but the app crashes immediately when the module is loaded... doesn't even reach the 32/64 bit condition

henon commented 2 years ago

Please download and compile the source code and try single stepping the loading routines. That way you can find out what happens and why things fail in your environment.

JimiC commented 2 years ago

@rvetere @FrizzTheSnail This is the cause of your troubles. This project is build with AMD64 as the architecture target. To target x86 you need to compile your own code.

MSB3270 There was a mismatch between the processor architecture of the project being built "x86" and the processor architecture of the reference "...\.nuget\packages\pythonnet_netstandard_py37_win\2.5.1\lib\netstandard2.0\Python.Runtime.dll", "AMD64". 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.

henon commented 1 year ago

By default Python.Included includes the amd64 python binaries. If you want the x86 binaries you can use the Python.Deployment nuget to download those binaries as shown in the examples.