在Mac OS X Mavericks (10.9)上,pip提示找不到stdio.h错误
我现在尝试了无数种解决方案,但似乎都没用。我想安装mysql-python,但这也发生在numpy和其他需要gcc的包上:
building '_mysql' extension
gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -isysroot /Developer/SDKs/MacOSX10.6.sdk -g -O2 -DNDEBUG -g -O3 -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/mysql/include -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.6-intel-2.7/_mysql.o -Os -g -fno-strict-aliasing -arch x86_64
In file included from _mysql.c:29:
/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:33:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^
1 error generated.
error: command 'gcc-4.2' failed with exit status 1
我想说的是:
我已经安装了命令行工具。
从/usr/bin/gcc创建了一个指向/usr/bin/gcc-4.2的符号链接。
gcc-4.2 --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix
我创建了一个虚拟的C文件,成功编译并运行了它,所以gcc本身是没问题的。
$ cat a.c
#include <stdio.h>
main()
{
printf("hello\n");
}
$ gcc-4.2 a.c
a.c:3:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
main()
^~~~
1 warning generated.
$ ./a.out
hello
为了保险起见,
$ xcode-select -p
/Library/Developer/CommandLineTools
到底发生了什么?!
编辑 - 忘了提到python的版本。
$ python
Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
编辑 - 有个令人兴奋的进展。设置这些变量有了一些进展:
$ export CFLAGS="-arch i386 -arch x86_64"
$ export FFLAGS="-m32 -m64"
$ export LDFLAGS="-Wall -undefined dynamic_lookup -bundle -arch i386 -arch x86_64"
$ export CC=gcc-4.2
$ export CXX="g++ -arch i386 -arch x86_64"
但是它又失败了,出现在
gcc-4.2 -bundle -undefined dynamic_lookup -isysroot /Developer/SDKs/MacOSX10.6.sdk -isysroot /Developer/SDKs/MacOSX10.6.sdk -g -Wall -undefined dynamic_lookup -bundle build/temp.macosx-10.6-intel-2.7/_mysql.o -L/usr/local/mysql/lib -lmysqlclient_r -o build/lib.macosx-10.6-intel-2.7/_mysql.so -arch x86_64
ld: library not found for -lSystem
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'gcc-4.2' failed with exit status 1
我怀疑这也是和命令行工具有关的类似错误。而且,为什么它使用的是“/Developer/SDKs/MacOSX10.6.sdk”?(抱歉问了些新手问题,我正在尝试从vim/unix迁移到pycharm/mac,但到目前为止进展不太顺利 :()
3 个回答
2
这个对我有效
xcode-select --install
15
从Mojave系统开始,单单使用 xcode-select --install
这个命令是不够的,你还需要安装一个可以在 /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
找到的包。来源:https://forums.developer.apple.com/thread/104296
2
正如@wegry上面提到的--
brew install python
确认使用
$ which python
/usr/local/homebrew/bin/python
这样做后,问题就完全解决了。成功通过pip安装了numpy和mysql-python!