pip在Mac OS X Mavericks(10.9)上报错:stdio.h未找到

10

到目前为止,我已经尝试了无数种解决方案,但似乎都不起作用。我正在尝试安装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,但目前进展不顺 :( )


你使用2.7.2有什么原因吗?我以为10.9已经预装了2.7.4。你是用brew安装的Python吗? - wegry
1
我从Snow Leopard升级,我猜Mavericks实际上没有升级Python?我没有手动安装它。 - beans
3
我建议您尝试安装Homebrew,并在此基础上使用命令“brew install python”来安装Python。这将同时安装pip,并检查您的命令行工具是否过时,以帮助解决相关问题。希望这能使您在MacOS上的操作更加顺畅。 - wegry
2
@wegry 我之前对此感到非常沮丧,所以暂时放弃了,但我又尝试了一下,这次成功了。非常感谢你!!! - beans
3个回答

14

从Mojave开始,xcode-select --install不再足够,您还应该安装可以在/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg找到的软件包。来源:https://forums.developer.apple.com/thread/104296


这对我也管用,不知道为什么现在变成了可选安装? - ChrisChinchilla

2
如上所述,@wegry提到 -
brew install python

确认与之一致
$ which python
/usr/local/homebrew/bin/python

我刚刚成功地使用pip安装了numpy和mysql-python,这完全消除了此前的问题!


我猜我在工具链方面做了一些更改(它们通过xcode的处理方式很混乱....),然后brew upgrade python对我起了作用!我猜它选择了自从第一次安装Python以来设置的新路径。 - Paschalis

2
这对我有用。
xcode-select --install

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接