简体   繁体   English

如何在 OS X Lion 上维护 Python 包?

[英]How do I maintain Python packages on OS X Lion?

What is the correct way to install and update Python packages on OS X Mountain Lion, using Apple's built in Python?使用 Apple 的内置 Python 在 OS X Mountain Lion 上安装和更新 Python 包的正确方法是什么?

I've tried all everything I can find here and in the documentation for various packages but keep encountering all kinds of errors that result in failed or aborted installations or updates.我已经尝试了所有可以在此处和文档中找到的各种软件包的所有内容,但不断遇到各种导致安装或更新失败或中止的错误。 Notably, with pip I frequently get errors like值得注意的是,使用pip我经常会遇到类似的错误

RuntimeError: maximum recursion depth exceeded in cmp RuntimeError:在 cmp 中超出最大递归深度

or或者

SError: [Errno 24] Too many open files: '/Library/Python/2.7/site-packages' SError:[Errno 24] 打开的文件太多:'/Library/Python/2.7/site-packages'

and some commands pip commands (like list ) just don't seem to exist at all.一些命令pip命令(如list )似乎根本不存在。

I have an uptodate version of pip that works fine with some packages, and have the latest Xcode command line tools installed.我有一个最新版本的pip可以很好地与某些软件包配合使用,并且安装了最新的 Xcode 命令行工具。

The only thing that seems to work — and it works all the time — is唯一似乎有效——而且一直有效——是

python setup.py install

Is this the correct way to maintain and install python packages on Lion?这是在 Lion 上维护和安装 python 包的正确方法吗? Is there any reason not to use this method as my primary method for keeping packages uptodate?有什么理由使用这种方法作为我保持软件包最新的主要方法吗? Should pip be working for me, or does it not work with Apple's Python? pip应该为我工作,还是不适用于 Apple 的 Python?


UPDATE: I spoke too soon.更新:我说得太早了。 I also have problems with我也有问题

python setup.py install

Occasionally (often) I'll get:偶尔(经常)我会得到:

error: /Library/Python/2.7/site-packages: Too many open files错误:/Library/Python/2.7/site-packages:打开的文件太多

When nothing is running in a fresh Terminal, I get about 50 when I当新终端中什么都没有运行时,我得到大约 50

lsof | grep python | wc -l

and if I quit Dropbox, which seems to be the source of these, and reduce the number to 0, I still get "Too many open files" for most package installation operations, with whatever tool I use, even after a reboot of my system.如果我退出 Dropbox,这似乎是这些的来源,并将数字减少到 0,对于大多数软件包安装操作,我仍然会得到“打开的文件太多”,无论我使用什么工具,即使在我的系统重新启动后.

Why am I getting a "too many open files" error so often?为什么我经常收到“打开的文件太多”错误?

You should be able to maintain exactly as you're doing, but likely need to update your PYTHONPATH to somewhere outside of /Library, hence the reason everyone else is mentioning that and/or using homebrew to install python.您应该能够完全按照您的方式进行维护,但可能需要将您的 PYTHONPATH 更新到 /Library 之外的某个位置,因此其他人都提到这一点和/或使用自制软件安装 python 的原因。

I install python packages with pip and maintain them using:我使用pip安装 python 包并使用以下方法维护它们:

https://github.com/nvie/pip-tools https://github.com/nvie/pip-tools

First of all, download and install the full Python from the python website .首先,从python 网站下载并安装完整的 Python。
Then use pip (or homebrew ).然后使用pip (或homebrew )。 The built-in python is incomplete in many respects, including mainly, the ability to install new packages.内置的python在很多方面都不完整,主要包括安装新包的能力。 I faced similar problems when I fist got my MacBookPro and installing the full python on top of the built-in one solved all my troubles当我拿到我的 MacBookPro 并在内置的上面安装完整的 python 解决了我所有的麻烦时,我遇到了类似的问题

Why use Apple's built-in Python?为什么要使用 Apple 的内置 Python? It's incomplete, I think.我认为它不完整。

I'm using Homebrew and brew install python works fine for me.我正在使用 Homebrew 和brew install python对我来说很好。

From https://github.com/mxcl/homebrew/wiki/Homebrew-and-Python :来自https://github.com/mxcl/homebrew/wiki/Homebrew-and-Python

We recommend to brew install python because:我们建议brew install python因为:

  • Comes with pip (and distribute)带有pip (和分发)
  • Python (distutils) finds brewed software (includes, libs), knows about the compiler and flags even if the command line tools for Xcode are not installed.即使没有安装 Xcode 的命令行工具,Python (distutils) 也会查找已编译的软件(包括、库),了解编译器和标志。
  • No need to set the PYTHONPATH for Homebrew bindings.无需为 Homebrew 绑定设置PYTHONPATH
  • No need to work-around the sudo -is-needed-for- easy_install issue无需解决sudo -is-needed-for- easy_install问题

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM