>>> import scrapy
>>> from scrapy.selector import HtmlXPathSelector
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/Scrapy-0.14.4-py2.7.egg/scrapy/selector /__init__.py", line 28, in <module>
from scrapy.selector.lxmlsel import *
File "/usr/local/lib/python2.7/site-packages/Scrapy-0.14.4-py2.7.egg/scrapy/selector /lxmlsel.py", line 7, in <module>
from scrapy.utils.misc import extract_regex
File "/usr/local/lib/python2.7/site-packages/Scrapy-0.14.4-py2.7.egg/scrapy/utils/misc.py", line 7, in <module>
from w3lib.html import remove_entities
File "/usr/local/lib/python2.7/site-packages/w3lib-1.2-py2.7.egg/w3lib/html.py", line 10, in <module>
from w3lib.url import safe_url_string
File "/usr/local/lib/python2.7/site-packages/w3lib-1.2-py2.7.egg/w3lib/url.py", line 11, in <module>
import cgi
File "/usr/local/lib/python2.7/cgi.py", line 51, in <module>
import mimetools
File "/usr/local/lib/python2.7/mimetools.py", line 6, in <module>
import tempfile
File "/usr/local/lib/python2.7/tempfile.py", line 34, in <module>
from random import Random as _Random
File "/usr/local/lib/python2.7/random.py", line 45, in <module>
from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
File "math.py", line 3, in <module>
from scrapy.selector import HtmlXPathSelector
ImportError: cannot import name HtmlXPathSelector
我正在使用python2.7,我曾经在ubuntu上工作,我从来没有遇到过这种问题,但是在CentOS中我得到了这个错误,顺便说一句,我安装了scrapy,这就是为什么你可以看到第一个命令完美运行
>>> import scrapy
>>> from scrapy.selector import HtmlXPathSelector
还有一件事,“来自scrapy.selector import HtmlXPathSelector”与math.py有什么关系,它位于同一个文件夹中
答案 0 :(得分:0)
嗯......这不是你的问题,而是CentOS与Ubuntu。
你是如何安装它的?使用pip
或yum
?
如果您从yum
安装了它,那么包裹很可能已损坏......
(出于好奇,最好知道你从哪里下载了包。)