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

Python.Include using pre-installed Python in Linux #53

Closed 167rgc911 closed 7 months ago

167rgc911 commented 1 year ago

Allows Python.Included to work with Linux which usually has Python pre-installed.

This came out due to the discussion in #52, but I honestly don't know if the OP of that question will find this useful. I use this as a test bed for an internal project since my dev system is Linux only.

Sample usage: https://github.com/167rgc911/Python.Included/blob/ppl_tests/examples/Python.Included.Linux/Program.cs https://github.com/167rgc911/Python.Included/blob/ppl_tests/examples/Python.Deployment.Linux/Program.cs

Limitations: This does not deploy any embedded Python versions as those are mostly Windows builds only.

Not really tested in Windows (but most of the touched code has "protection" and gets called in case of a Linux environment only).

Even with Python pre-installed in most Linux distributions, the installation directories are typically not writable by normal users. Using Virtual environments (venv) are a good option as the module installation code will not need modifications and you will have less chance of thrashing the system installed Python.

167rgc911 commented 1 year ago

Honestly this seem to be bad code :-( I can use pythonnet by itself to achieve this.

henon commented 1 year ago

Sure you can ;). I think the main value of Python.Included and Python.Deployment is for Windows where you can not count on a pre-existing Python installation. By the way, if you want a plug-and-play solution for linux, you might also not want to depend on the installed python version. You might want a very specific version and not mess with the pre-installed one.

henon commented 1 year ago

As for the bad code, the installer class could be injected with a WindowsInstaller or a LinuxInstaller depending on the runtime detection, but you don't have to do that. You could also add your examples though, so that others can try them out in their environments.

167rgc911 commented 1 year ago

Found a bug!

I just ran the sample codes on a clean env and the installed modules in the virtual env are not found by pythonnet.

167rgc911 commented 1 year ago

Sure you can ;). I think the main value of Python.Included and Python.Deployment is for Windows where you can not count on a pre-existing Python installation. By the way, if you want a plug-and-play solution for linux, you might also not want to depend on the installed python version. You might want a very specific version and not mess with the pre-installed one.

might be usable for Linux https://github.com/codrsquad/portable-python

henon commented 1 year ago

Are you still working on this or is it ready to be merged?

167rgc911 commented 1 year ago

Are you still working on this or is it ready to be merged?

still working