How can I get the version defined in setup.py (setuptools) in my package?

前端 未结 16 837
无人及你
无人及你 2020-11-27 09:47

How could I get the version defined in setup.py from my package (for --version, or other purposes)?

16条回答
  •  天命终不由人
    2020-11-27 10:40

    With a structure like this:

    setup.py
    mymodule/
            / __init__.py
            / version.py
            / myclasses.py
    

    where version.py contains:

    __version__ = 'version_string'
    

    You can do this in setup.py:

    import sys
    
    sys.path[0:0] = ['mymodule']
    
    from version import __version__
    

    This won't cause any problem with whatever dependencies you have in your mymodule/__init__.py

提交回复
热议问题