Skip to content

Support a AnyCpy / Any Python build #910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rmadsen-ks opened this issue Jul 10, 2019 · 8 comments
Closed

Support a AnyCpy / Any Python build #910

rmadsen-ks opened this issue Jul 10, 2019 · 8 comments

Comments

@rmadsen-ks
Copy link
Contributor

I suggest to remove all the defines, e.g PYTHON2, PYTHON3, PYTHON27, PYTHON3X, MONO_LINUX... And make it possible to define this at run-time.

I have an application where I don't know the operative system and I don't know which Python the users use (at compile time). The users will select the python version to use at run-time, depending on what they have installed. Currently, this has forced me to ship Python.Runtime.dll in 9 different versions: {Linux , Windows 32, Window 64} X {Python 2.7, 3.6 and 3.7}. Making me dread the day Python 3.8 gets out and I'll have to ship 12 different versions. And this is not even taking the 'm' and 'd' options into account.

In theory, a Python.Runtime built for python 3.6 should also work with 3.7, the only issue is figuring out what the python library is called: libpython3.6, libpython3.7, ...

Even the PYTHON2/PYTHON3 defines could be replaced by a Python.Runtime.IsPython2 bool in most cases (I believe all).

The only issue is then figuring out which python version to use at run time. Here, if you want, it could be a compile time flag, with a way of overriding it in run-time.

I might implement this myself if the maintainers think it's a good idea.

@filmor
Copy link
Member

filmor commented Jul 10, 2019

This is the explicit plan already. I've recently merged #894 that goes in this direction, further pull requests that drop usages of defines are highly appreciated. Since P/Invoke is not a good fit for this approach, though (since the Mono method of using __Internal as the library name and pre-loading the library directly before use is not universally supported), we are looking into switching to delegates instead, see https://mail.python.org/pipermail/pythondotnet/2019-July/002067.html.

@lostmsu looked into this before, but wanted to implement some simple benchmarking to see how much this would regress performance.

To find out which Python version to use at runtime I'd like to make the version and library path explicit parameters to the Runtime.Initialize function.

@rmadsen-ks
Copy link
Contributor Author

Sounds great! I was not aware that it was explicitly planned.

The P/Invoke stuff would have to go, but I cannot imaging there would be any significant performance penalty using delegate, Marshal.GetDelegateForFunctionPointer and friends.

In any case having a benchmark would be good. Also enables profiling performance issues that might already be in the interface between CLR and Python.

@lostmsu
Copy link
Member

lostmsu commented Jul 11, 2019

@rmadsen-ks https://www.nuget.org/packages/Python.Runtime.UnofficialNetStandard/ currently does that. We are planning to upstream the necessary changes.

@rmadsen-ks
Copy link
Contributor Author

@lostmsu sounds great! Any way I can download the source?

@lostmsu
Copy link
Member

lostmsu commented Jul 12, 2019

@rmadsen-ks it is in this one: https://github.com/losttech/pythonnet , branch losttech/master . It is diverged a bit though.

@rmadsen-ks
Copy link
Contributor Author

@lostmsu, thanks, will check it out.

@trippyeast
Copy link

@lostmsu, I'm having trouble building the branch you linked. I'm working on a project with similar requirements as @rmadsen-ks. Are there any updates about the effort to remove compilation symbols from the build?

@lostmsu
Copy link
Member

lostmsu commented Feb 21, 2021

This have now been implemented in Python.NET 3.0 (preview available in master and on NuGet). One needs to set Runtime.PythonDLL before doing any other calls though, otherwise might get TypeInitializationException

@lostmsu lostmsu closed this as completed Feb 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants