1

在单个 python 脚本中记录导入模块的版本的最佳方式或 PEP 约定是什么?有时我不得不使用由于模块不兼容而无法运行的旧脚本(例如,脚本是使用 pandas 0.15.0 和 matplotlib 1.3.0 编写的,现在我使用 pandas 0.18.1 和 matplotlib 1.5.1)。例如,如果脚本的第一部分在注释中包含 pandas(和其他导入的模块)版本,那就太好了,例如:

"""my_script_version = '0.0.1'
pandas_version = '0.15.0'
matplotlib_version = '1.3.0'
other_imported_module_version = 'x.y.z'
"""

或者有没有官方的方法可以做到这一点?比如使用一些元数据?

__version__ = '0.0.1'
__date__ = '2016-06-06'
__author__ = 'ragesz'

__pandas_version__ = '0.15.0'
__matplotlib_version__ = '1.3.0'
__other_imported_module_version__ = 'x.y.z'

谢谢!

4

2 回答 2

2

关于您的问题, PEP 518最近已被接受。

依赖项必须存储在特定文件中pyproject.toml

[build-system]
# Minimum requirements for the build system to execute.
requires = ["setuptools", "wheel"]  # PEP 508 specifications.

PEP 508为需求指定语法。

于 2016-06-06T16:02:19.283 回答
1

在脚本中添加信息的最佳方式是使用元数据,例如:

__version__="1.0.2"
__appname__="name script"
__author__="author"
__description__="short description"
__long_description__="long description for your script"
__author_email__="author@gmail.com"
于 2016-06-06T16:22:09.637 回答