我在ubuntu 12.04上安装了scrapy,在virtualenv中安装了python 3.5.2。我在安装scrapy时遇到了很多麻烦,但我终于安装了所有要求。我不得不手动安装twisted以完成安装,但我安装了Twisted 17.0。但是,当我尝试运行教程时,我收到以下错误:
Traceback (most recent call last):
File "/usr/local/bin/scrapy", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/local/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2927, in <module>
@_call_aside
File "/usr/local/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2913, in _call_aside
f(*args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2940, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/usr/local/lib/python3.5/site-packages/pkg_resources/__init__.py", line 635, in _build_master
ws.require(__requires__)
File "/usr/local/lib/python3.5/site-packages/pkg_resources/__init__.py", line 943, in require
needed = self.resolve(parse_requirements(requirements))
File "/usr/local/lib/python3.5/site-packages/pkg_resources/__init__.py", line 829, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'Twisted>=13.1.0' distribution was not found and is required by Scrapy
已安装Twisted 17.0,似乎正在运行。当我导入scrapy并在python中扭曲时,我没有错误(它找到了模块),但作为一个命令,scrapy不起作用。
Python 3.5.2 (default, Nov 2 2016, 11:15:44)
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import scrapy
>>> import twisted
答案 0 :(得分:0)
您需要为所涉及的所有扩展模块安装构建依赖项。这将包括至少gcc,libffi-dev和libssl-dev(但可能更多):
sudo apt-get install gcc libffi-dev libssl-dev
安装了构建依赖项后,您应该将 Python 软件的所有安装到virtualenv中。
virtualenv --python=python3.5 scrapy-environment
. scrapy-environment/bin/activate
pip install scrapy
scrapy ...
如果您遇到此错误,则应更新问题以包含该错误的详细信息。