macos 如何在 Mac OS X 10.7.4 上安装 lxml?我已经用尽了所有选择

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10666578/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 09:11:09  来源:igfitidea点击:

How do I install lxml on Mac OS X 10.7.4? I have exhausted all options

pythonmacososx-lioninstalllxml

提问by ThinkCode

Tried various avenues but no luck. I am using a MBP with 10.7.4. I don't remember the last time I had so many problems installing anything with Python on my Mac. Please help me use lxml on my local machine and not rely on SVN commits, updates to remotely run on the Linux machine.

尝试了各种途径,但没有运气。我正在使用 10.7.4 的 MBP。我不记得上次我在 Mac 上使用 Python 安装任何东西时遇到这么多问题是什么时候。请帮助我在本地机器上使用 lxml,而不是依赖 SVN 提交、更新以在 Linux 机器上远程运行。

$ sudo STATIC_DEPS=true /usr/bin/easy_install-2.7 lxml
Password:
Searching for lxml
Reading http://pypi.python.org/simple/lxml/
Reading http://codespeak.net/lxml
Best match: lxml 2.3.4
Downloading http://lxml.de/files/lxml-2.3.4.tgz
Processing lxml-2.3.4.tgz
Running lxml-2.3.4/setup.py -q bdist_egg --dist-dir /tmp/easy_install-mbyEtk/lxml-2.3.4/egg-dist-tmp-O_t_3P
Building lxml version 2.3.4.
Latest version of libiconv is 1.14
Downloading libiconv into libs/libiconv-1.14.tar.gz
error: [Errno 60] Operation timed out

Tried the following with no luck

尝试了以下没有运气

$ python setup.py build

$ python setup.py build

$ STATIC_DEPS=true sudo easy_install --allow-hosts=lxml.de,*.python.org lxml
$ sudo pip install lxml

llvm-gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -I/usr/include/libxml2 -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.macosx-10.7-intel-2.7/src/lxml/lxml.etree.o -w -flat_namespace

unable to execute llvm-gcc-4.2: No such file or directory

error: command 'llvm-gcc-4.2' failed with exit status 1

回答by larsks

I first installed MacPortsand then:

我首先安装了MacPorts,然后:

$ sudo port install python27 py27-lxml

And this gave me a functioning lxml installation.

这给了我一个正常运行的 lxml 安装。

Regarding your error messages, you appear to be missing the compiler command that pipis using to build lxml(llvm-gcc-4.2). Do you have the OS X development tools installed? You should find that file in /usr/bin/llvm-gcc-4.2; if it's not there, you probably need to download and install the development package.

关于您的错误消息,您似乎缺少pip用于构建的编译器命令lxml(llvm-gcc-4.2)。您是否安装了 OS X 开发工具?您应该在/usr/bin/llvm-gcc-4.2; 中找到该文件。如果它不存在,您可能需要下载并安装开发包。

You can install the XCode developer tools via the App Store. If you read the comments in the app store, you'll note that in order to make the command line tools available you need to install them separately. In XCode, go to Preferences->Downloads and download the "Command line tools" package.

您可以通过 App Store 安装 XCode 开发人员工具。如果您阅读应用商店中的评论,您会注意到为了使命令行工具可用,您需要单独安装它们。在 XCode 中,转到 Preferences->Downloads 并下载“命令行工具”包。

回答by user1337226

To future users who are going over this page, here is a step-by-step guide to installing lxml on Mac OSX.

对于浏览此页面的未来用户,这里是在 Mac OSX 上安装 lxml 的分步指南。

  1. Go to Xcode, and go to Preferences, and then go to the Downloads tab, and select "Command Line Tools". Download Command Line Tools

  2. Go to Applications, then Utilities, and then Terminal, and open the Terminal. In terminal, type "easy_install pip". Note: If it says "error: /usr/local/bin/pip: Permission denied", then type "chmod 777 /usr/local/bin/". now try step 2 again.

  3. Type: pip install "Cython>=0.18"

  4. After it is finished, type: pip install lxml

  5. Open up python IDLE and test if you can import lxml, have fun!

  1. 转到 Xcode,然后转到首选项,然后转到下载选项卡,然后选择“命令行工具”。下载命令行工具

  2. 依次转到应用程序、实用程序和终端,然后打开终端。在终端中,输入“easy_install pip”。注意:如果显示“错误:/usr/local/bin/pip:权限被拒绝”,则输入“chmod 777 /usr/local/bin/”。现在再次尝试第 2 步。

  3. 类型:pip install "Cython>=0.18"

  4. 完成后,输入:pip install lxml

  5. 打开python IDLE,测试是否可以导入lxml,玩得开心!

回答by janex

I had to do: "sudo port uninstall py-lxml", "sudo port uninstall py24-lxml", and "sudo port install py27-lxml" and then I uninstalled lxml with pip, and re-installed with pip and it worked!

我不得不这样做:“ sudo port uninstall py-lxml”,“ sudo port uninstall py24-lxml”和“ sudo port install py27-lxml”然后我用pip卸载了lxml,并用pip重新安装,它起作用了!