发布于 4年前

如何解决pip install Twisted时出错: limits.h: No such file or directory

Environment: macOS mojave - 10.14.1; python 2.7.15/python 3.7.1.

在使用pip安装Twisted库时出现以下错误:

In file included from /usr/local/lib/gcc/x86_64-apple-darwin15.6.0/7.1.0/include-fixed/syslimits.h:7:0,
                 from /usr/local/lib/gcc/x86_64-apple-darwin15.6.0/7.1.0/include-fixed/limits.h:34,
                 from /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:19,
                 from src/twisted/test/raiser.c:4:
/usr/local/lib/gcc/x86_64-apple-darwin15.6.0/7.1.0/include-fixed/limits.h:194:15: fatal error: limits.h: No such file or directory
 #include_next <limits.h>  /* recurse down to the real one */
               ^~~~~~~~~~
compilation terminated.
error: Setup script exited with error: command 'gcc' failed with exit status 1

在网上搜了很久,仅发现针对linux的解决方案。没有人提到macOS。

在一番研究后,发现macOS mojave的update故意删除了/user/include。于是想到是否因为/usr/include不存在了,所以pip找不到limit.h了呢。

于是执行了下面这行命令,重新手动恢复/usr/include文件夹。

open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

可以看到/usr/include文件夹被恢复了。

在这之后再执行

pip install Twisted

结果显示successfully installed:

Collecting twisted
  Using cached https://files.pythonhosted.org/packages/5d/0e/a72d85a55761c2c3ff1cb968143a2fd5f360220779ed90e0fadf4106d4f2/Twisted-18.9.0.tar.bz2
Requirement already satisfied: zope.interface>=4.4.2 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from twisted) (4.6.0)
Requirement already satisfied: constantly>=15.1 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from twisted) (15.1.0)
Requirement already satisfied: incremental>=16.10.1 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from twisted) (17.5.0)
Requirement already satisfied: Automat>=0.3.0 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from twisted) (0.7.0)
Requirement already satisfied: hyperlink>=17.1.1 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from twisted) (18.0.0)
Requirement already satisfied: PyHamcrest>=1.9.0 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from twisted) (1.9.0)
Requirement already satisfied: attrs>=17.4.0 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from twisted) (18.2.0)
Requirement already satisfied: setuptools in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from zope.interface>=4.4.2->twisted) (39.0.1)
Requirement already satisfied: six in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from Automat>=0.3.0->twisted) (1.11.0)
Requirement already satisfied: idna>=2.5 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from hyperlink>=17.1.1->twisted) (2.7)
Building wheels for collected packages: twisted
  Running setup.py bdist_wheel for twisted ... done
  Stored in directory: /Users/Mescetina/Library/Caches/pip/wheels/57/2e/89/11ba83bc08ac30a5e3a6005f0310c78d231b96a270def88ca0
Successfully built twisted

苹果macOS 10.14的更新去除了/usr/include,导致pip找不到header文件,从而阻止了Twisted库的安装。希望我的solution能帮到大家。

©2020 edoou.com   京ICP备16001874号-3