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
321 stars 52 forks source link

.NET Core and error with ImportModule #61

Closed rcalado closed 10 months ago

rcalado commented 10 months ago

Imported project into a new .NET core MVC application and also into an AWS C# Lambda project.

Both projects are throwing 'PythonEngine' does not contain a definition for 'ImportModule'.

Is there a way to leverage your component within a .NET Core application?

Just trying to get the basic setup implemented and running into issues

await Installer.SetupPython(); PythonEngine.Initialize(); dynamic sys=PythonEngine.ImportModule("sys"); Console.WriteLine("Python version: " + sys.version);

henon commented 10 months ago

Which version of Python.Included and which Version of .NET Core?

.Net Core is supported. We have an example project in the repo that demonstrates it. Maybe it has to be updated for newer versions of Python.Included. I'll check, once I have your version numbers.

rcalado commented 10 months ago

.NET Core 6 and I didn't specify a Python Version. I assumed that would grab the latest 3.11 version?

Didn't see a way to specify a lower version number to test against. I didn't spot the .netcore3.1 sample earlier so thank you for alerting me to that.
Unfortunately, there are some errors that still occur running that version against 3.1 or 6.0

See below for the console logs.

Downloading Pip... Downloading Pip... Downloading Pip... There was a problem downloading pip: The process cannot access the file 'C:\Temp\Python.Included-main\Python.Included-main\examples\Python.Included.Example.NetCore\bin\Debug\net6.0\python-3.11.0-embed-amd64\Lib\get-pip.py' because it is being used by another process. There was a problem downloading pip: The process cannot access the file 'C:\Temp\Python.Included-main\Python.Included-main\examples\Python.Included.Example.NetCore\bin\Debug\net6.0\python-3.11.0-embed-amd64\Lib\get-pip.py' because it is being used by another process.

cmd.exe /C "C:\Temp\Python.Included-main\Python.Included-main\examples\Python.Included.Example.NetCore\bin\Debug\net6.0\python-3.11.0-embed-amd64\Scripts\pip" install "spacy" cmd.exe /C "C:\Temp\Python.Included-main\Python.Included-main\examples\Python.Included.Example.NetCore\bin\Debug\net6.0\python-3.11.0-embed-amd64\Scripts\pip" install "spacy"

The system cannot find the path specified.

The system cannot find the path specified.

=> exit code 1 => exit code 1 Could not find platform dependent libraries 0.05% 0.60% 1.23% 1.85% 2.47% ... 96.94% 97.57% 98.19% 98.81% 100.00% Done!

cmd.exe /C cd "C:\Temp\Python.Included-main\Python.Included-main\examples\Python.Included.Example.NetCore\bin\Debug\net6.0\python-3.11.0-embed-amd64" && python.exe Lib\get-pip.py

Python version:

3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)]

Current working directory:

C:\Temp\Python.Included-main\Python.Included-main\examples\Python.Included.Example.NetCore\bin\Debug\net6.0

PythonPath:

C:\Temp\Python.Included-main\Python.Included-main\examples\Python.Included.Example.NetCore\bin\Debug\net6.0\python-3.11.0-embed-amd64\python311.zip;C:\Temp\Python.Included-main\Python.Included-main\examples\Python.Included.Example.NetCore\bin\Debug\net6.0\python-3.11.0-embed-amd64\Lib;C:\Temp\Python.Included-main\Python.Included-main\examples\Python.Included.Example.NetCore\bin\Debug\net6.0\python-3.11.0-embed-amd64\DLLs

henon commented 10 months ago

OK, I fixed the problem.RunCommand which was called by PipInstallModule had an error, it should have wrapped the command of cmd.exe /C in quotes. After I fixed this the .net core example runs fine with .net 6. Releasing new nugets.

henon commented 10 months ago

https://www.nuget.org/packages/Python.Deployment/2.0.5 https://www.nuget.org/packages/Python.Included/3.11.6