我刚刚安装了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 in place of easy_install。使用pip,您可以使用
在大多数linux系统中,您可以通过管道将其传递到
grep
(或在Windows上为findstr
)以查找您感兴趣的特定包的行:对于单个模块,您可以尝试^{} attribute ,但是有些模块没有它:
最后,由于问题中的命令以
sudo
作为前缀,因此看起来您正在安装到全局python环境中。强烈建议查看pythonvirtual environment管理器,例如virtualenvwrapper使用与
setuptools
库一起分发的pkg_resources
模块。请注意,传递给get_distribution
方法的字符串应该对应于PyPI条目。如果要从命令行运行它,可以执行以下操作:
请注意,传递给
get_distribution
方法的字符串应该是在PyPI中注册的包名,而不是试图导入的模块名。不幸的是,这些并不总是相同的(例如,你做了
pip install memcached
,但是import memcache
)。相关问题 更多 >
编程相关推荐