[英]Installing lxml with python on a mac
首先,我在不使用pip的情況下安裝了lxml(Mac OS 10.6.8上的Python 2.7.2)。 然后,我讀了這篇文章,然后我再次使用pip( sudo pip install lxml
)安裝它。 我還有一個問題:
我可以導入lxml( import lxml
)但我無法使用from lxml import etree
。 我有這個錯誤消息:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lxml-2.3.3-py2.7-macosx-10.6-intel.egg/lxml/etree.so, 2): Symbol not found: _htmlParseChunk
Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lxml-2.3.3-py2.7-macosx-10.6-intel.egg/lxml/etree.so
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lxml-2.3.3-py2.7-macosx-10.6-intel.egg/lxml/etree.so
然后,我嘗試按照這些說明從源安裝lxml,並且我有以下錯誤消息:
checking whether we are cross compiling... configure: error: in `/Users/my_name/Applications/lxml/lxml-2.2.2/build/tmp/libxml2-2.7.8':
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details
Traceback (most recent call last):
File "setup.py", line 115, in <module>
STATIC_CFLAGS, STATIC_BINARIES),
File "/Users/my_name/Applications/lxml/lxml-2.2.2/setupinfo.py", line 50, in ext_modules
libxslt_version=OPTION_LIBXSLT_VERSION)
File "/Users/my_name/Applications/lxml/lxml-2.2.2/buildlibxml.py", line 198, in build_libxml2xslt
call_subprocess(configure_cmd, cwd=libxml2_dir, **call_setup)
File "/Users/my_name/Applications/lxml/lxml-2.2.2/buildlibxml.py", line 158, in call_subprocess
raise Exception('Command "%s" returned code %s' % (cmd_desc, returncode))
Exception: Command "./configure --without-python --disable-dependency-tracking --disable-shared --prefix=/Users/my_name/Applications/lxml/lxml-2.2.2/build/tmp/libxml2" returned code 1
最后,我按照這個答案的第二個建議,我使用命令行sudo STATIC_DEPS=true /usr/bin/easy_install-2.7 lxml
。 它在Apple提供的系統Python 2.7上安裝了lxml,而不是我當前使用的版本。 積極的一點:如果我運行Apple-Python,我可以from lxml import etree
。
否定點:我仍然不知道如何在另一個版本的python上安裝lxml。 任何的想法?
我目前正在使用/Library/Frameworks/Python.framework/Versions/2.7/bin/python
。
您需要為正在使用的Python版本安裝單獨的easy_install
。 有關詳細信息,請參閱此處的答案。 然后,您可以使用它運行easy_install
命令:
STATIC_DEPS=true easy_install-2.7 lxml
更新:從您的評論中,您現在報告的權限錯誤顯示另一個Python路徑,一個似乎是MacPorts安裝的Python: /opt/local/Library/Frameworks
。 您需要確定要使用的Python。 事實上,如果你想使用MacPorts,那么只需安裝MacPorts提供的lxml
端口即可。 這是最簡單的解決方案。
$ sudo port selfupdate
$ sudo port install py27-lxml
否則,您需要使用另一個(python.org?)Python 2.7.2安裝easy_install
。 我建議使用Distribute
,它是`setuptools'的更現代的分支,你需要確保使用正確的Python:
$ curl -O http://python-distribute.org/distribute_setup.py
$ export PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
$ which python2.7 # should be in the path above
$ python2.7 distribute_setup.py
$ STATIC_DEPS=true easy_install-2.7 lxml
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.