Python/Pip的C包PyProj在使用GCC编译时无法通过编译。

6

我正在尝试通过 virtualenvpipWebFaction虚拟机上安装PyProj,但是遇到了编译错误。我使用的命令如下:

$ pip install pyproj

有很多输出,最终以这个结束:

src/geodesic.c: In function ‘InverseStart’:

src/geodesic.c:1093: error: ISO C90 forbids mixed declarations and code

error: command 'gcc' failed with exit status 1

----------------------------------------
Command "/home/<user>/webapps/<webapp>/env/py34/bin/python3.4 -c "import setuptools, tokenize;__file__='/tmp/pip-build-ow1vcsjk/pyproj/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-cl2pbd20-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/<user>/webapps/<webapp>/env/py34/include/site/python3.4" failed with error code 1 in /tmp/pip-build-ow1vcsjk/pyproj

我不太确定从哪里开始。根据这个SO问题,问题在于PyProj兼容C90,我可以尝试使用C99进行编译。只是猜测而已。
如前所述,这是在具有shell访问权限的远程VM上。我的开发机(Mac)上有一个匹配的Virtualenv,可以顺利编译。但是,有不同的编译器:
开发环境:
$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)

VM:

$ gcc --version
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-11)

有什么想法吗?谢谢您的帮助。
1个回答

8
问题在于您的虚拟机上的 GCC 版本默认使用 ISO C90 标准,但 pyproj 代码与该标准不兼容。要强制 GCC 使用 C99 标准,您需要相应地设置 CFLAGS 环境变量,请尝试:
export CFLAGS='-std=c99'

然后再次运行pip install pyproj。我使用healpy时遇到了同样的问题,这对我有用。

我把这个标记为已回答,因为它看起来是正确的答案;不过我没有那个虚拟机设置来检查它。当我再次开始该项目时,我会再试一次,但这可能需要一段时间。无论如何,谢谢! - allanberry

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