问题
I am using python 2.7 and I am trying to use lxml, but when I try using lxml.etree, I get this error:
RuntimeWarning: compiletime version 2.6 of module 'lxml.etree' does not match runtime version 2.7
And then this error:
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
I have tried installing using easy_install and using pip
After installing, I see this message:
Installed /usr/lib/python2.6/site-packages/lxml-2.3.3-py2.6-linux-x86_64.egg
回答1:
Make sure you're using the right easy_install and pip. When easy_install and pip get installed, they're 'mated' with a version of python via a symlink by whatever version of python you used to install them.
If you're using python-2.7, make sure you use easy_install-2.7, or pip-2.7. Odds are the pip you used was mated with 2.6 and it's symlink is 'pip -> pip2.6'.
If you're using python2.7, make sure easy_install and pip's symlinks are set correctly. (This should be as simple as finding easy_install, and replacing it to point to easy_install-2.7, then run easy_install pip and pip will replace it's own link.
To replace easy_install with the correct version:
wget http://peak.telecommunity.com/dist/ez_setup.py
python2.7 ez_setup.py
That should replace your existing easy_install with one that uses the correct python version. Reinstall pip using it, and whatever other modules you need.
回答2:
I'm using python 2.7, pip 2.8 and i'm getting this as error while installing bs4 package. Can anyone help me. Below is the stack trace:
python is /usr/local/bin/python
System is Running Required Python version :2.7
Python to be used : /usr/local/bin/python
pip is /usr/bin/pip
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/bs4/__init__.py", line 30, in <module>
from .builder import builder_registry, ParserRejectedMarkup
File "/usr/lib/python2.7/site-packages/bs4/builder/__init__.py", line 317, in <module>
from . import _lxml
File "/usr/lib/python2.7/site-packages/bs4/builder/_lxml.py", line 9, in <module>
from lxml import etree
File "lxml.etree.pyx", line 134, in init lxml.etree (src/lxml/lxml.etree.c:187500)
TypeError: encode() argument 1 must be string without null bytes, not unicode
bs4 is not installed. Installing latest available version...
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/bs4/__init__.py", line 30, in <module>
from .builder import builder_registry, ParserRejectedMarkup
File "/usr/lib/python2.7/site-packages/bs4/builder/__init__.py", line 317, in <module>
from . import _lxml
File "/usr/lib/python2.7/site-packages/bs4/builder/_lxml.py", line 9, in <module>
from lxml import etree
File "lxml.etree.pyx", line 134, in init lxml.etree (src/lxml/lxml.etree.c:187500)
TypeError: encode() argument 1 must be string without null bytes, no
来源:https://stackoverflow.com/questions/9465248/runtimewarning-compiletime-version-2-6-of-module-lxml-etree-does-not-match-ru