我遇到了一个非常奇怪的问题,用PyCharm运行Scrapy:
使用完全相同的配置,Debug可以工作,但使用PyCharm运行不起作用。
配置: PyCharm Edit Configuration Page
当我尝试调试scrapy时,它完美无缺。 当我尝试运行scrapy时,我得到以下错误:
C:\Users\baib2\AppData\Local\Programs\Python\Python36\python.exe
C:/Users/baib2/AppData/Local/Programs/Python/Python36/Lib/site-packages/scrapy/cmdline.py crawl scenelist_spider
Traceback (most recent call last):
File "C:/Users/baib2/AppData/Local/Programs/Python/Python36/Lib/site-packages/scrapy/cmdline.py", line 8, in <module
import scrapy
File "C:\Users\baib2\AppData\Local\Programs\Python\Python36\lib\site-packages\scrapy\__init__.py", line 27, in <module
from . import _monkeypatches
File "C:\Users\baib2\AppData\Local\Programs\Python\Python36\lib\site-packages\scrapy\_monkeypatches.py", line 20, in <module
import twisted.persisted.styles # NOQA
File "C:\Users\baib2\AppData\Local\Programs\Python\Python36\lib\site-packages\twisted\persisted\styles.py", line 21, in <module
from twisted.python.compat import _PY3, _PYPY
File "C:\Users\baib2\AppData\Local\Programs\Python\Python36\lib\site-packages\twisted\python\__init__.py", line 11, in <module
from .compat import unicode
File "C:\Users\baib2\AppData\Local\Programs\Python\Python36\lib\site-packages\twisted\python\compat.py", line 612, in <module
from http import cookiejar as cookielib
File "C:\Users\baib2\AppData\Local\Programs\Python\Python36\Lib\site-packages\scrapy\http\__init__.py", line 8, in <module
from scrapy.http.headers import Headers
File "C:\Users\baib2\AppData\Local\Programs\Python\Python36\lib\site-packages\scrapy\http\__init__.py", line 10, in <module
from scrapy.http.request import Request
File "C:\Users\baib2\AppData\Local\Programs\Python\Python36\lib\site-packages\scrapy\http\request\__init__.py", line 8, in <module
from w3lib.url import safe_url_string
File "C:\Users\baib2\AppData\Local\Programs\Python\Python36\lib\site-packages\w3lib\url.py", line 17, in <module
from six.moves.urllib.request import pathname2url, url2pathname
File "C:\Users\baib2\AppData\Local\Programs\Python\Python36\lib\site-packages\six.py", line 92, in __get__
result = self._resolve()
File "C:\Users\baib2\AppData\Local\Programs\Python\Python36\lib\site-packages\six.py", line 160, in _resolve
module = _import_module(self.mod)
File "C:\Users\baib2\AppData\Local\Programs\Python\Python36\lib\site-packages\six.py", line 82, in _import_module
__import__(name)
File "C:\Users\baib2\AppData\Local\Programs\Python\Python36\lib\urllib\request.py", line 88, in <module
import http.client
ModuleNotFoundError: No module named 'http.client'
Process finished with exit code 1
无需附加任何代码,因为即使运行命令:
python3.exe C:\Users\baib2\AppData\Local\Programs\Python\Python36\Lib\site-packages\scrapy\cmdline.py
会产生同样的错误。
我已经检查了 sys.path ,与run相比,debug还有1条路径:
'C:\ Program Files(x86)\ JetBrains \ PyCharm 2016.3.3 \ helpers \ pydev'
我真的不认为这会有任何不同。
希望有人可以看看,谢谢!
答案 0 :(得分:6)
菜单运行&gt;编辑配置 启用复选框“之后显示命令行” 这对我有帮助
答案 1 :(得分:0)
如果您使用的是新版本的PyCharm,其中Show Command line afterward
不再可用,Run with Python console
解决了这个问题。
答案 2 :(得分:0)
我也花了一些时间来追踪类似的问题。
我的问题是我有一个名为http
的本地模块,该模块当然没有名为client
的子模块。 here描述了另一个类似的问题。
解决方案是通过编辑配置更改此测试调用的工作目录。