我刚刚安装了python模块。construct
和statlib
与setuptools
这样安装。
# Install setuptools to be able to download the following
sudo apt-get install python-setuptools
# Install statlib for lightweight statistical tools
sudo easy_install statlib
# Install construct for packing/unpacking binary data
sudo easy_install construct
我希望能够(通过编程)检查它们的版本。 是否有与python --version
相当的东西,我可以从命令行运行?
我的python版本是2.7.3
。
我建议使用[pip来代替easy_install](https://stackoverflow.com/a/3220572/1265154)。使用pip,你可以用以下方法列出所有已安装的软件包和它们的版本
pip freeze
在大多数Linux系统中,你可以用管道将其输送到grep
(或Windows中的findstr
),以找到你感兴趣的特定软件包的行。
Linux:
$ pip freeze | grep lxml
lxml==2.3
Windows:
c:\> pip freeze | findstr lxml
lxml==2.3
对于单个模块,你可以尝试使用__version__
属性,但也有一些模块没有这个属性。
$ python -c "import requests; print(requests.__version__)"
2.14.2
$ python -c "import lxml; print(lxml.__version__)"
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute '__version__'
最后,由于你问题中的命令以sudo
为前缀,看来你是在安装到全局的python环境。强烈建议你查看一下python的virtual environment管理器,例如virtualenvwrapper