Skip to main content
 首页 » 编程设计

MacOSX : no module named twisted. internet 和 gcc 4.0 下的 Python Scrapy

2025年05月04日11insus

我是一个python新手,想自学Scrapy,第一步就失败了... 我安装好 Scrapy,并按照 http://doc.scrapy.org/en/latest/intro/tutorial.html 上的说明进行操作.

在终端输入“scrapy startproject tutorial”后,它返回

Traceback (most recent call last): 
  File "/Library/Frameworks/Python.framework/Versions/2.7/bin/scrapy", line 3, in <module> 
    from scrapy.cmdline import execute 
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-        packages/scrapy/cmdline.py", line 7, in <module> 
    from scrapy.crawler import CrawlerProcess 
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-    packages/scrapy/crawler.py", line 3, in <module> 
    from twisted.internet import reactor, defer 
ImportError: No module named twisted.internet 

然后我去下载twisted,它需要gcc-4.0,我没有找到它的下载。我的 python2.7.3 似乎在 gcc4.0.1 上运行,但我不知道哪里出错了...这是我在终端中键入“pip install twisted”后的最后几行(虽然我的 pip 正在运行) :

gcc-4.0 -fno-strict-aliasing -fno-common -dynamic -g -O2 -DNDEBUG -g -O3 -arch i386 -arch x86_64 -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c twisted/test/raiser.c -o build/temp.macosx-10.3-intel-2.7/twisted/test/raiser.o 
 
unable to execute gcc-4.0: No such file or directory 
 
error: command 'gcc-4.0' failed with exit status 1 

Command     /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -c "import setuptools;__file__='/var/folders/ww/7vcs04j95jg4dgcb94t7s5p00000gn/T/pip-build/twisted/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/ww/7vcs04j95jg4dgcb94t7s5p00000gn/T/pip-lfT0hS-record/install-record.txt --single-version-externally-managed failed with error code 1 in /var/folders/ww/7vcs04j95jg4dgcb94t7s5p00000gn/T/pip-build/twisted 

我的 Mac 在 MACOSX 10.7.5 上运行,我从未安装 Xcode。

感谢任何帮助!

请您参考如下方法:

我在 OSX 上遇到了 Scrapy 的确切问题。我通过以下方式修复了它:

  • 从 App Store 安装 Xcode
  • 打开 Xcode
  • 转到“首选项”
  • 选择“下载”标签
  • 安装命令行工具