简体   繁体   English

在Mac上安装lxml时遇到问题,安装但未找到模块

[英]Problems installing lxml on a Mac, it installs but module not found

The code 编码

from lxml import etree 

produces the error 产生错误

ImportError: No module named lxml 

Running 运行

sudo easy_install lxml

results in 结果是

lxml 2.2.7 is already the active version in easy-install.pth 
Removing lxml-2.2.7-py2.5-macosx-10.3-i386.egg from site-packages and rerunning sudo easy_install lxml results in
Adding lxml 2.2.7 to easy-install.pth file
Installed /Library/Python/2.5/site-packages/lxml-2.2.7-py2.5-macosx-10.3-i386.egg
Processing dependencies for lxml
Finished processing dependencies for lxml

And yet I still get No module named lxml 然而我仍然得到没有名为lxml的模块

What step am I missing in order to use lxml on my Mac (OSX 10.5)? 为了在我的Mac(OSX 10.5)上使用lxml,我错过了什么步骤?

Update 更新

python --version reports python --version报告

Python 2.5.2

and running python produces 并运行python生成

Python 2.5.2 (r252:60911, Feb 22 2008, 07:57:53) 
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin

You appear to be trying to easy_install lxml into the Apple-supplied Python 2.5 for OS X 10.5 but using an egg that was likely built with a python.org Python 2.5. 您似乎正在尝试将easy_install lxml轻松安装到Apple提供的OS 2.5 for OS X 10.5中,但使用的是可能使用python.org Python 2.5构建的egg。 If you have both installed on your system, keep in mind that you need to have a separate easy_install (setuptools or Distribute) for each Python. 如果您已在系统上安装了这两个系统,请记住,您需要为每个Python单独安装easy_install (setuptools或Distribute)。 Apple supplies one in /usr/bin for its Python. Apple为其Python提供/usr/bin中的一个。 Ensuring that you are using the python.org one (check which python ), you should follow the installation instructions for setuptools or Distribute to install an easy_install for it. 确保您使用的是python.org(检查which python ),您应该按照setuptools的安装说明或Distribute为它安装easy_install That easy_install will be in the bin directory of the python.org framework: /Library/Frameworks/Python.framework/Versions/2.5//bin . easy_install将位于python.org框架的bin目录中: /Library/Frameworks/Python.framework/Versions/2.5//bin Use that easy_install to install lxml ; 使用easy_install来安装lxml ; it should then automatically end up in /Library/Frameworks/Python.framework/Versions/2.5/lib . 它应该自动结束于/Library/Frameworks/Python.framework/Versions/2.5/lib There is a more detailed discussion of a similar problem here and here . 这里这里有一个类似问题的更详细的讨论。

You have multiple versions of python installed on your computer. 您的计算机上安装了多个版本的python。 lxml is installed for one, and you're invoking the other. 为一个安装了lxml ,你正在调用另一个。 There's not enough context to divine any more than that. 除此之外,还没有足够的背景来神圣。

sudo env ARCHFLAGS="-arch x86_64" easy_install-2.7 lxml

适用于Mac OS 10.9。

STATIC_DEPS=true sudo pip install lxml

它的工作原理见http://lxml.de/build.html#building-lxml-on-macos-x

Some thing is not right here. 这有些不对劲。 The package being added is lxml-2.2.7-py2.5-macosx-10.3-i386.egg It refers to mac os x 10.3 , while you are using mac os x 10.5. 添加的包是lxml-2.2.7-py2.5-macosx-10.3-i386.egg它指的是mac os x 10.3,而你使用的是mac os x 10.5。

Try python --version, what does that tell you? 尝试python --version,这告诉你什么?

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

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