我使用setuptools安装了Python模块construct和statlib:
sudo apt-get install python-setuptools
sudo easy_install statlib
sudo easy_install construct
如何从命令行检查它们的版本?
我使用setuptools安装了Python模块construct和statlib:
sudo apt-get install python-setuptools
sudo easy_install statlib
sudo easy_install construct
如何从命令行检查它们的版本?
当前回答
有些模块没有__version__属性,所以最简单的方法是在terminal: pip列表中检查
其他回答
模块。__version__是一个很好的尝试,但它并不总是有效。
如果你不想退出,并且你正在使用pip 8或9,你仍然可以使用pip.get_installed_distribution()从Python内部获取版本:
这里的解决方案适用于pip 8和9,但在pip 10中,该函数已从pip中移动。get_installed_distribution到pip._internal.utils.misc。get_installed_distribution显式地指出它不供外部使用。如果您正在使用pip 10+,那么依赖它不是一个好主意。
import pip
pip.get_installed_distributions() # -> [distribute 0.6.16 (...), ...]
[
pkg.key + ': ' + pkg.version
for pkg in pip.get_installed_distributions()
if pkg.key in ['setuptools', 'statlib', 'construct']
] # -> nicely filtered list of ['setuptools: 3.3', ...]
假设我们使用的是Jupyter Notebook(如果使用的是Terminal,去掉感叹号):
如果软件包(例如xgboost)与pip一起安装: 皮普秀xgboost !pip freeze | grep xgboost !pip list | grep xgboost 如果这个包(例如caffe)是用Conda安装的: conda list caffe
总而言之:
conda list
(它将提供所有的库以及版本细节。)
And:
pip show tensorflow
(它提供了完整的图书馆细节。)
你可以试试
>>> import statlib
>>> print statlib.__version__
>>> import construct
>>> print contruct.__version__
这是PEP 396推荐的方法。但是PEP从未被接受,并且一直被推迟。事实上,Python核心开发人员似乎越来越支持不包含__version__属性,例如在Remove importlib_metadata.version..
在Python 3.8版本中,importlib包中有一个新的元数据模块,它也可以做到这一点。
下面是文档中的一个例子:
>>> from importlib.metadata import version
>>> version('requests')
'2.22.0'