我正在使用 python 2.7,并且我正在尝试使用 lxml ,但是当我尝试使用 lxml.etree 时,出现此错误:
RuntimeWarning: compiletime version 2.6 of module 'lxml.etree' does not match runtime version 2.7
然后出现这个错误:
File "lxml.etree.pyx", line 123, in init lxml.etree (src/lxml/lxml.etree.c:160385) TypeError: encode() argument 1 must be string without null bytes, not unicode
我尝试使用 easy_install 和 pip 进行安装
安装后,我看到以下消息:
Installed /usr/lib/python2.6/site-packages/lxml-2.3.3-py2.6-linux-x86_64.egg
最佳答案
确保您使用正确的 easy_install 和 pip。安装 easy_install 和 pip 后,它们会通过符号链接(symbolic link)与您用来安装它们的 Python 版本“配对”。
如果您使用的是 python-2.7,请确保使用 easy_install-2.7 或 pip-2.7。您使用的 pip 很可能与 2.6 配对,并且其符号链接(symbolic link)是“pip -> pip2.6”。
如果您使用的是 python2.7,请确保 easy_install 和 pip 的符号链接(symbolic link)设置正确。 (这应该像找到 easy_install 一样简单,并将其替换为指向 easy_install-2.7,然后运行 easy_install pip ,pip 将替换它自己的链接。
要将 easy_install 替换为正确的版本:
wget http://peak.telecommunity.com/dist/ez_setup.py
python2.7 ez_setup.py
这应该将您现有的 easy_install 替换为使用正确 python 版本的版本。使用它重新安装 pip 以及您需要的任何其他模块。
关于python - 模块 'lxml.etree' 的 RuntimeWarning : compiletime version 2. 6 与运行时版本 2.7 不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9465248/