简体   繁体   English

如何找出我的 Mac 上安装了哪些 Python 库?

[英]How do I find out what Python libraries are installed on my Mac?

I'm just starting out with Python, and have found out that I can import various libraries.我刚开始使用 Python,发现我可以导入各种库。 How do I find out what libraries exist on my Mac that I can import?如何找出我可以导入的 Mac 上存在哪些库? How do I find out what functions they include?我如何找出它们包含哪些功能?

I seem to remember using some web server type thing to browse through local help files, but I may have imagined that!我似乎记得使用一些 Web 服务器类型的东西来浏览本地帮助文件,但我可能已经想到了!

From the Python REPL (the command-line interpreter / Read-Eval-Print-Loop), type help("modules") to see a list of all your available libs.在 Python REPL(命令行解释器 / Read-Eval-Print-Loop)中,输入help("modules")以查看所有可用库的列表。

Then to see functions within a module, do help("posix") , for example.然后要查看模块中的函数,例如执行help("posix") If you haven't import ed the library yet, you have to put quotes around the library's name.如果您还没有import库,则必须在库名称周围加上引号。

For the web server, you can run the pydoc module that is included in the python distribution as a script:对于 Web 服务器,您可以将 Python 发行版中包含的pydoc模块作为脚本运行:

python /path/to/pydoc.py -p 1234

where 1234 is the port you want the server to run at.其中1234是您希望服务器运行的端口。 You can then visit http://localhost:1234/ and browse the documentation.然后您可以访问http://localhost:1234/并浏览文档。

Every standard python distribution has these libraries, which cover most of what you will need in a project.每个标准的 Python 发行版都有这些库,它们涵盖了您在项目中需要的大部分内容。

In case you need to find out if a library exists at runtime, you do it like this如果您需要在运行时找出库是否存在,您可以这样做

try:
    import ObscureModule
except ImportError:
    print "you need to install ObscureModule"
    sys.exit(1) # or something like that

You can install another library: yolk.您可以安装另一个库:yolk。

yolk is a python package manager and will show you everything you have added via pypi. yolk 是一个 python 包管理器,它会显示你通过 pypi 添加的所有内容。 But it will also show you site-packages added through whatever local package manager you run.但它也会向您显示通过您运行的任何本地包管理器添加的站点包。

只需运行 Python interpeter 并键入命令 import "lib_name" 如果出现错误,则您没有安装 lib ......否则你很高兴

On Leopard, depending on the python package you're using and the version number, the modules can be found in /Library/Python:在 Leopard 上,根据您使用的 python 包和版本号,可以在 /Library/Python 中找到模块:

/Library/Python/2.5/site-packages /Library/Python/2.5/site-packages

or in /Library/Frameworks或在 /Library/Frameworks

/Library/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages /Library/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages

(it could also be 3.0 or whatever version)... I guess it is quite the same with Tiger (也可以是 3.0 或其他版本)...我猜 Tiger 也差不多

Considering that in every operating system most of python's packages are installed using 'pip' (see pip documentation ) you can also use the command 'pip freeze' on a terminal to print a list of all the packages you have installed through it.考虑到在每个操作系统中,大多数 python 包都是使用“pip”安装的(请参阅pip 文档),您还可以在终端上使用命令“pip freeze”来打印通过它安装的所有包的列表。 Other tools like 'homebrew' for macOS (used when for some reason you can't install a package using pip) have similar commands, in this specific case 'brew list' .其他工具,如 macOS 的 'homebrew'(在由于某种原因无法使用 pip 安装软件包时使用)具有类似的命令,在这种特定情况下为'brew list'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尽管我用 pip 安装了我的 python3,但我如何在我的 mac 中找到 IDLE? - how can i find IDLE in my mac though i installed my python3 with pip? 我在Mac上安装了python 2.7和3.6。 如何找到与Python3相关的pip版本? - I have python 2.7 and 3.6 installed on my mac. How to find the version of pip associated with Python3? 我的 python 文件如何访问已安装的库 (Pip) - How do my python files get access to installed libraries (Pip) 如何告诉我的 Mac 使用安装在我的计算机上的最新版本的 Python? - How do I tell my Mac to use the latest version of Python installed on my computer? 我如何找出我的代码的哪些部分在Python中效率低下 - How do I find out what parts of my code are inefficient in Python 我的Mac上安装了多个Python副本吗? - Do i have multiple copies of Python installed on my Mac? 如何查看python中已安装的库? - how can I see my installed libraries in python ? 我如何找出 python class 中的哪些属性是可调用的? - How do i find out what attributes in a python class are callable? 如何找出OSX上安装了哪些不同版本的Python? - How can I find out what different versions of Python installed on OSX? 如何使用 Python 找出我的 PYTHONPATH? - How do I find out my PYTHONPATH using Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM