Part of maintaining a Django-based application like MDN's kuma is ensuring Python packages are up to date. I was recently testing an upgrade on a remote system and needed to ensure that a given Python package was at the version number it should be. Here's how I retrieved the package version:
维护MDN的kuma之类的基于Django的应用程序的一部分是确保Python软件包是最新的。 我最近正在远程系统上测试升级,因此需要确保给定的Python软件包的版本号应为该版本号。 这是我检索软件包版本的方法:
import nose # Nose is a test utility. Replace with your desired package here.
nose.__version__
# Output: 0.3.1
The __version__
property returns the exact version number for a Python package. Some Python packages use a VERSION
property as well, but __version__
should be the most reliable.
__version__
属性返回Python软件包的确切版本号。 一些Python包也使用VERSION
属性,但是__version__
应该是最可靠的。