解决scrapy创建项目失败异常问题汇总
问题一 lxml问题:
由于window7系统内安装了2.x和3.x,需要使用py -3 -m scrapy startproject;过程中出现创建项目失败:
Traceback (most recent call last):
File "D:\Python36\lib\runpy.py", line 183, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "D:\Python36\lib\runpy.py", line 142, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "D:\Python36\lib\runpy.py", line 109, in _get_module_details
__import__(pkg_name)
File "D:\Python36\lib\site-packages\scrapy\__init__.py", line 34, in <module>
from scrapy.spiders import Spider
File "D:\Python36\lib\site-packages\scrapy\spiders\__init__.py", line 10, in <module>
from scrapy.http import Request
File "D:\Python36\lib\site-packages\scrapy\http\__init__.py", line 11, in <module>
from scrapy.http.request.form import FormRequest
File "D:\Python36\lib\site-packages\scrapy\http\request\form.py", line 11, in <module>
import lxml.html
File "D:\Python36\lib\site-packages\lxml\html\__init__.py", line 54, in <module>
from .. import etree
ImportError: cannot import name 'etree'
ImportError: cannot import name ‘etree’
解决方法:
- py - 3 -m pip uninstall lxml 卸载原有版本lxml
- py -3 -m pip install lxml 重新安装系统推荐版本
- 推荐科学上网buff加持
问题二 cryptography问题:
Traceback (most recent call last):
File "D:\Python36\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "D:\Python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "D:\Python36\lib\site-packages\scrapy\__main__.py", line 4, in <module>
execute()
File "D:\Python36\lib\site-packages\scrapy\cmdline.py", line 145, in execute
cmd.crawler_process = CrawlerProcess(settings)
File "D:\Python36\lib\site-packages\scrapy\crawler.py", line 270, in __init__
log_scrapy_info(self.settings)
File "D:\Python36\lib\site-packages\scrapy\utils\log.py", line 149, in log_scrapy_info
for name, version in scrapy_components_versions()
File "D:\Python36\lib\site-packages\scrapy\utils\versions.py", line 35, in scrapy_components_versions
("pyOpenSSL", _get_openssl_version()),
File "D:\Python36\lib\site-packages\scrapy\utils\versions.py", line 43, in _get_openssl_version
import OpenSSL
File "D:\Python36\lib\site-packages\OpenSSL\__init__.py", line 8, in <module>
from OpenSSL import crypto, SSL
File "D:\Python36\lib\site-packages\OpenSSL\crypto.py", line 12, in <module>
from cryptography import x509
File "D:\Python36\lib\site-packages\cryptography\x509\__init__.py", line 8, in <module>
from cryptography.x509.base import (
File "D:\Python36\lib\site-packages\cryptography\x509\base.py", line 16, in <module>
from cryptography.x509.extensions import Extension, ExtensionType
File "D:\Python36\lib\site-packages\cryptography\x509\extensions.py", line 18, in <module>
from cryptography.hazmat.primitives import constant_time, serialization
File "D:\Python36\lib\site-packages\cryptography\hazmat\primitives\constant_time.py", line 9, in <module>
from cryptography.hazmat.bindings._constant_time import lib
ImportError: DLL load failed: %1 不是有效的 Win32 应用程序。
ImportError: DLL load failed: %1 不是有效的 Win32 应用程序。
或者
ImportError: DLL load failed: 操作系统无法运行1% 这个可能解决其它问题吧,顺便贴出来
解决方法:
- py - 3 -m pip I cryptography 重新安装cryptography
- 推荐科学上网buff加持