报错如下:
python@ubuntu:~/PycharmProjects/untitled$ scrapy startproject haha
Traceback (most recent call last):
File "/usr/local/bin/scrapy", line 7, in <module>
from scrapy.cmdline import execute
File "/usr/local/lib/python3.5/dist-packages/scrapy/cmdline.py", line 9, in <module>
from scrapy.crawler import CrawlerProcess
File "/usr/local/lib/python3.5/dist-packages/scrapy/crawler.py", line 7, in <module>
from twisted.internet import reactor, defer
File "/usr/local/lib/python3.5/dist-packages/twisted/internet/reactor.py", line 38, in <module>
from twisted.internet import default
File "/usr/local/lib/python3.5/dist-packages/twisted/internet/default.py", line 56, in <module>
install = _getInstallFunction(platform)
File "/usr/local/lib/python3.5/dist-packages/twisted/internet/default.py", line 44, in _getInstallFunction
from twisted.internet.epollreactor import install
File "/usr/local/lib/python3.5/dist-packages/twisted/internet/epollreactor.py", line 24, in <module>
from twisted.internet import posixbase
File "/usr/local/lib/python3.5/dist-packages/twisted/internet/posixbase.py", line 18, in <module>
from twisted.internet import error, udp, tcp
File "/usr/local/lib/python3.5/dist-packages/twisted/internet/tcp.py", line 31, in <module>
from twisted.internet._newtls import (
File "/usr/local/lib/python3.5/dist-packages/twisted/internet/_newtls.py", line 21, in <module>
from twisted.protocols.tls import TLSMemoryBIOFactory, TLSMemoryBIOProtocol
File "/usr/local/lib/python3.5/dist-packages/twisted/protocols/tls.py", line 41, in <module>
from OpenSSL.SSL import Error, ZeroReturnError, WantReadError
File "/usr/local/lib/python3.5/dist-packages/OpenSSL/__init__.py", line 8, in <module>
from OpenSSL import crypto, SSL
File "/usr/local/lib/python3.5/dist-packages/OpenSSL/SSL.py", line 194, in <module>
if _lib.Cryptography_HAS_SSL_ST:
AttributeError: module 'lib' has no attribute 'Cryptography_HAS_SSL_ST'
原因:我试过csdn其它博客处理类似报错后的方法,发现不适合我。同一种报错背后会有多种原因,我这里是因为scrapy包只安装在pip,没有安装在pip3,但我用的是python3的包。
解决办法:输入 sudo pip3 install scrapy。 它会把我还没安装好包给安装好,现在可以使用scrapy框架了。
python@ubuntu:~/PycharmProjects/untitled$ scrapy startproject alibaba
:0: UserWarning: You do not have a working installation of the service_identity module: 'cannot import name 'opentype''. Please install it from <https://pypi.python.org/pypi/service_identity> and make sure all of its dependencies are satisfied. Without the service_identity module, Twisted can perform only rudimentary TLS client hostname verification. Many valid certificate/hostname mappings may be rejected.
New Scrapy project 'alibaba', using template directory '/usr/local/lib/python3.5/dist-packages/scrapy/templates/project', created in:
/home/python/PycharmProjects/untitled/alibaba
You can start your first spider with:
cd alibaba
scrapy genspider example example.com
python@ubuntu:~/PycharmProjects/untitled$ cd alibaba/