我试图在Python 2中使用Scrapy,我收到了这个错误,
File "/Library/Python/2.7/site-packages/twisted/internet/defer.py", line 1386, in _inlineCallbacks
result = g.send(result)
File "/Library/Python/2.7/site-packages/scrapy/crawler.py", line 95, in crawl
six.reraise(*exc_info)
File "/Library/Python/2.7/site-packages/scrapy/crawler.py", line 77, in crawl
self.engine = self._create_engine()
File "/Library/Python/2.7/site-packages/scrapy/crawler.py", line 102, in _create_engine
return ExecutionEngine(self, lambda _: self.stop())
File "/Library/Python/2.7/site-packages/scrapy/core/engine.py", line 69, in __init__
self.downloader = downloader_cls(crawler)
File "/Library/Python/2.7/site-packages/scrapy/core/downloader/__init__.py", line 88, in __init__
self.middleware = DownloaderMiddlewareManager.from_crawler(crawler)
File "/Library/Python/2.7/site-packages/scrapy/middleware.py", line 58, in from_crawler
return cls.from_settings(crawler.settings, crawler)
File "/Library/Python/2.7/site-packages/scrapy/middleware.py", line 34, in from_settings
mwcls = load_object(clspath)
File "/Library/Python/2.7/site-packages/scrapy/utils/misc.py", line 44, in load_object
mod = import_module(module)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Library/Python/2.7/site-packages/scrapy/downloadermiddlewares/httpproxy.py", line 4, in <module>
from urllib2 import _parse_proxy
ImportError: cannot import name _parse_proxy
我安装了urllib2
Name: urllib2
Version: 1498656401.94
Summary: Checking out the typosquatting state of PyPi
Home-page: https://github.com/benjaoming
Author: Benjamin Bach
Author-email: benjamin@overtag.dk
License: MIT
Location: /usr/local/lib/python2.7/site-packages
Requires:
我已尝试卸载并重新安装urllib2和请求。
答案 0 :(得分:0)
您可能有两种不同的Python环境。 Scrapy似乎生活在/Library/Python/2.7/site-packages/scrapy
,而你的urllib2生活在/usr/local/lib/python2.7/site-packages
。