Jef*_*Fay 183
如果您有pip安装,并且想要查看使用安装程序工具安装的软件包,您只需调用:
pip freeze
Run Code Online (Sandbox Code Playgroud)
它还将包含已安装软件包的版本号.
更新
pip已更新,也可pip freeze通过调用生成相同的输出:
pip list
Run Code Online (Sandbox Code Playgroud)
注意
输出pip list的格式不同,因此如果您有一些shell脚本解析输出(可能要获取版本号)freeze并想要更改要调用的脚本list,则需要更改解析代码.
Ash*_*ary 45
help('modules') 应该为你做.
在IPython中:
In [1]: import #import press-TAB
Display all 631 possibilities? (y or n)
ANSI audiodev markupbase
AptUrl audioop markupsafe
ArgImagePlugin avahi marshal
BaseHTTPServer axi math
Bastion base64 md5
BdfFontFile bdb mhlib
BmpImagePlugin binascii mimetools
BufrStubImagePlugin binhex mimetypes
CDDB bisect mimify
CDROM bonobo mmap
CGIHTTPServer brlapi mmkeys
Canvas bsddb modulefinder
CommandNotFound butterfly multifile
ConfigParser bz2 multiprocessing
ContainerIO cPickle musicbrainz2
Cookie cProfile mutagen
Crypto cStringIO mutex
CurImagePlugin cairo mx
DLFCN calendar netrc
DcxImagePlugin cdrom new
Dialog cgi nis
DiscID cgitb nntplib
DistUpgrade checkbox ntpath
Run Code Online (Sandbox Code Playgroud)
小智 27
如果你想获得有关已安装的python发行版的信息,并且不想使用你的cmd控制台或终端,而是通过python代码,你可以使用以下代码(使用python 3.4测试):
import pip #needed to use the pip functions
for i in pip.get_installed_distributions(local_only=True):
print(i)
Run Code Online (Sandbox Code Playgroud)
该pip.get_installed_distributions(local_only=True)函数调用返回一个迭代并且因为for循环和打印功能的包含在可迭代的元素被打印出由新行字符分开(\n).结果将(取决于您安装的发行版)看起来像这样:
cycler 0.9.0
decorator 4.0.4
ipykernel 4.1.0
ipython 4.0.0
ipython-genutils 0.1.0
ipywidgets 4.0.3
Jinja2 2.8
jsonschema 2.5.1
jupyter 1.0.0
jupyter-client 4.1.1
#... and so on...
Run Code Online (Sandbox Code Playgroud)
你可以试试:蛋黄
对于安装蛋黄,请尝试:
easy_install yolk
Run Code Online (Sandbox Code Playgroud)
Yolk是一个Python工具,用于获取有关已安装的Python包的信息以及查询可用于PyPI(Python包索引)的包.
您可以查看哪些软件包处于活动状态,非活动状态或处于开发模式,并通过查询PyPI向您显示哪些软件包具有更新版本.
我的看法:
#!/usr/bin/env python3
import pkg_resources
dists = [str(d).replace(" ","==") for d in pkg_resources.working_set]
for i in dists:
print(i)
Run Code Online (Sandbox Code Playgroud)
从命令行
python -c help('modules')
Run Code Online (Sandbox Code Playgroud)
可用于查看所有模块和特定模块
python -c help('os')
Run Code Online (Sandbox Code Playgroud)
对于Linux下面将工作
python -c "help('os')"
Run Code Online (Sandbox Code Playgroud)
要在更高版本的pip(在上测试)上运行此命令,请pip==10.0.1使用以下命令:
from pip._internal.operations.freeze import freeze
for requirement in freeze(local_only=True):
print(requirement)
Run Code Online (Sandbox Code Playgroud)
是!你应该使用pip作为你的python包管理器(http://pypi.python.org/pypi/pip)
用pip安装包,你可以做一个
pip freeze
Run Code Online (Sandbox Code Playgroud)
它将列出所有已安装的软件包.您可能也应该使用virtualenv和virtualenvwrapper.当你开始一个新项目时,你可以做到
mkvirtualenv my_new_project
Run Code Online (Sandbox Code Playgroud)
然后(在那个virtualenv内),做
pip install all_your_stuff
Run Code Online (Sandbox Code Playgroud)
这样,您可以workon my_new_project随后pip freeze查看为该virtualenv /项目安装的软件包.
例如:
? ~ mkvirtualenv yo_dude
New python executable in yo_dude/bin/python
Installing setuptools............done.
Installing pip...............done.
virtualenvwrapper.user_scripts creating /Users/aaylward/dev/virtualenvs/yo_dude/bin/predeactivate
virtualenvwrapper.user_scripts creating /Users/aaylward/dev/virtualenvs/yo_dude/bin/postdeactivate
virtualenvwrapper.user_scripts creating /Users/aaylward/dev/virtualenvs/yo_dude/bin/preactivate
virtualenvwrapper.user_scripts creating /Users/aaylward/dev/virtualenvs/yo_dude/bin/postactivate
virtualenvwrapper.user_scripts creating /Users/aaylward/dev/virtualenvs/yo_dude/bin/get_env_details
(yo_dude)? ~ pip install django
Downloading/unpacking django
Downloading Django-1.4.1.tar.gz (7.7Mb): 7.7Mb downloaded
Running setup.py egg_info for package django
Installing collected packages: django
Running setup.py install for django
changing mode of build/scripts-2.7/django-admin.py from 644 to 755
changing mode of /Users/aaylward/dev/virtualenvs/yo_dude/bin/django-admin.py to 755
Successfully installed django
Cleaning up...
(yo_dude)? ~ pip freeze
Django==1.4.1
wsgiref==0.1.2
(yo_dude)? ~
Run Code Online (Sandbox Code Playgroud)
或者如果你有一个带有requirements.pip文件的python包,
mkvirtualenv my_awesome_project
pip install -r requirements.pip
pip freeze
Run Code Online (Sandbox Code Playgroud)
会做的
| 归档时间: |
|
| 查看次数: |
252379 次 |
| 最近记录: |