Is there a good way to determine at runtime which python versions are supported? · pythonnet/pythonnet · Discussion #1724

Discussion options

Often we have multiple versions of python installed, although not idea. For example, most often I find python 3.7 or 3.8 in parallel with 3.9.

When I'm using pythonnet 2.5.1 I would like to flag in my UI somehow that 3.9 is not supported, so I can react, like change some paths or switch the version to 3.7 or 3.8.
I would like to make a check, get all installed python versions, and a list of the supported ones by python.NET, to exclude the unsupported ones in my app.

Is there a good way to determine this at runtime?

You must be logged in to vote
Comment options

You must be logged in to vote

4 replies

@Mikhinja

Comment options

Thanks Victor!
Is there anything that can list, at runtime, the supported versions by python.NET?

My use case is that my app is an add-in and doesn't install python.NET itself, so I can't just hardcode a value.

One very hacky way I can think of is to try and find Python.Runtime.dll (relying on a relative path), and listing the generated namespaces TypeOffsetXY where X is the major version and Y is the minor version, for example TypeOffset37. But this is sort of a hacky way and very prone to errors.

Is there a good way of finding out what are the supported versions by python.NET, at runtime?

@filmor

Comment options

We could expose this as a property or function in the DLL (only for 3.0 onwards, I don't think we will make another 2.5 release).

@Mikhinja

Comment options

Ok, good to know. And yes, I believe that would be a good thing to have going forward.
Thank you, Benedikt!

@cdfarrow

Comment options

We could expose this as a property or function in the DLL (only for 3.0 onwards, I don't think we will make another 2.5 release).

That would be helpful. I've just put a hard-wired check for Python <= 3.8 into my library to avoid mysterious exceptions when it runs with Python 3.10.