如何解决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能帮到大家。
相关推荐
twistedcruller 2020-05-09
Twistedworld 2019-12-22
cairencong 2011-03-07
TwistedNerve 2008-11-24
宿舍 2019-10-20
xuxingzhuang 2012-05-29
Wendywubowen 2019-04-15
efeve 2018-08-08
TwistedFa 2014-11-08
paopao00 2017-05-11
mengdg000 2016-09-25
CoderBoom 2015-09-17
TwistedNerve 2015-09-17
TwistedFate 2015-09-16
twistedcruller 2015-09-15
Twistedjungle 2019-06-21
Fatetwisted 2014-02-24
TwistedFate 2018-08-21
twisted 2017-08-18