Skip to main content
 首页 » 编程设计

python之为python3安装Scrapy时出错

2025年05月04日2152php

我使用 pip 在 Ubuntu 中为 Python3 安装了 Scrapy

sudo pip3 install scrapy 

安装的时候报错

x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.5m -c src/twisted/test/raiser.c -o build/temp.linux-x86_64-3.5/src/twisted/test/raiser.o 
    src/twisted/test/raiser.c:4:20: fatal error: Python.h: No such file or directory 
    compilation terminated. 
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 

Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-_il8a07a/Twisted/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-9935fpm4-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-_il8a07a/Twisted/ 

请您参考如下方法:

如前所述,您缺少开发依赖项

对于 python 2

sudo apt install -y python-dev 
sudo pip install scrapy 

对于 python 3

sudo apt install -y python3-dev 
sudo pip3 install scrapy