Skip to content

Ability to find pythonnet version at runtime / define __version__ #1909

Closed

Description

@amueller

Details

  • I would like to be able to find out which version of pythonnet is installed in a particular runtime environment from the python side. Most packages define a package.__version__ for that purpose. I couldn't find anything like that in pythonnet.

I tried

    print(pythonnet.__version__)
    print([v for v in dir(pythonnet) if "version" in v])

I checked on pythonnet==3.0.0rc4.

Activity

  1. added this to the 3.0.0 milestone on Sep 9, 2022
  2. lostmsu commented on Sep 15, 2022

    @lostmsu
    Member

    As a workaround you could do

    from Python.Runtime import PyObject
    clr.GetClrType(PyObject).Assembly.GetName().Version
  3. lostmsu commented on Sep 15, 2022

    @lostmsu
    Member

    Actually, there's already clr.__version__

  4. filmor commented on Sep 16, 2022

    @filmor
    Member

    I'd like to adjust the build process to add a version to pythonnet directly, instead. To read the clr version, you have to have initialised the .NET runtime already.

  5. reopened this on Sep 16, 2022
  6. filmor commented on Sep 17, 2022

    @filmor
    Member

    @amueller Is this really necessary nowadays? Since Python 3.8, there is importlib.metadata.version which will work even when you just do python setup.py build in the local checkout. In the end, I would just use this one to define __version__ as well, just on 3.7 we'd need to fall back to pkg_resources which introduces a runtime dependency on setuptools.

  7. amueller commented on Sep 19, 2022

    @amueller
    Author

    I was actually unaware of that. Thank you, that indeed makes it unnecessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions