0
>>> 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 导入 HtmlXPathSelector”与同一文件夹中的 math.py 有什么关系

4

1 回答 1

0

嗯......这不是你的问题,而是 CentOS 与 Ubuntu 的问题。

你是怎么安装的?使用pipyum

如果您从yum很可能安装它的包被破坏......(只是出于好奇,很高兴知道您从哪里下载包)。

于 2012-10-17T05:49:15.707 回答