一个简单的 Python SWIG 错误问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/648482/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 20:32:39  来源:igfitidea点击:

A trivial Python SWIG error question

pythonswig

提问by Alex

I am trying to get Python running with swig to do C/C++. I am running the tutorial here, 'building a python module'. When I do the call

我正在尝试使用 swig 运行 Python 来执行 C/C++。我在这里运行教程,'构建一个 python 模块'。当我打电话时

gcc -c example.c example_wrap.c -I /my_correct_path/python2.5

I get an error:

我收到一个错误:

my_correct_path/python2.5/pyport.h:761:2: error: #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
example_wrap.c: In function 'SWIG_Python_ConvertFunctionPtr':
example_wrap.c:2034: warning: initialization discards qualifiers from pointer target type
example_wrap.c: In function 'SWIG_Python_FixMethods':
example_wrap.c:3232: warning: initialization discards qualifiers from pointer target type

It actually does create an example.o file, but it doesn't work. I am using python2.5 not 2.1 as in the example, is this a problem? The error (everything else is just a 'warning') says something about wrong platform. This is a 64bit machine; is this a problem? Is my gcc configured wrong for my machine? How do I get past this?

它实际上确实创建了一个 example.o 文件,但它不起作用。我使用的是 python2.5 而不是示例中的 2.1,这是一个问题吗?错误(其他一切都只是“警告”)说明了有关错误平台的信息。这是一台 64 位机器;这是一个问题吗?我的机器的 gcc 配置错误吗?我该如何度过这一关?

UPDATE: I am still having problems. How do I actually implement this "fix"?

更新:我仍然有问题。我如何实际实施这个“修复”?

回答by haridsv

I found this thread looking for an answer for the same "LONGBIT" error while installing python readline for 32bit python on 64bit centos. The link doesn't have the direct answer, so I had to google further for the answer (which might be straight-forward for seasoned linux users/devs). For future reference, the solution is to force 32-bit by using "-m32" in CFLAGS environment variable.

在 64 位 centos 上为 32 位 python 安装 python readline 时,我发现这个线程正在寻找相同“LONGBIT”错误的答案。该链接没有直接答案,所以我不得不进一步搜索答案(对于经验丰富的 linux 用户/开发人员来说,这可能是直截了当的)。为了将来参考,解决方案是通过在 CFLAGS 环境变量中使用“-m32”来强制使用 32 位。

bash-3.2$ easy_install readline
Searching for readline
Reading http://pypi.python.org/simple/readline/
Reading http://www.python.org/
Best match: readline 2.6.4
Downloading http://pypi.python.org/packages/source/r/readline/readline-2.6.4.tar.gz#md5=7568e8b78f383443ba57c9afec6f4285
Processing readline-2.6.4.tar.gz
Running readline-2.6.4/setup.py -q bdist_egg --dist-dir /tmp/easy_install-mqr9wH/readline-2.6.4/egg-dist-tmp-p3apfF
In file included from /usr/local/python2.6/include/python2.6/Python.h:58,
                 from Modules/readline.c:8:
/usr/local/python2.6/include/python2.6/pyport.h:685:2: error: #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
error: Setup script exited with error: command 'gcc' failed with exit status 1

I then tried with CFLAGS=-m32:

然后我尝试使用 CFLAGS=-m32:

bash-3.2$ CFLAGS=-m32 easy_install readline
Searching for readline
Reading http://pypi.python.org/simple/readline/
Reading http://www.python.org/
Best match: readline 2.6.4
Downloading http://pypi.python.org/packages/source/r/readline/readline-2.6.4.tar.gz#md5=7568e8b78f383443ba57c9afec6f4285
Processing readline-2.6.4.tar.gz
Running readline-2.6.4/setup.py -q bdist_egg --dist-dir /tmp/easy_install-uauVci/readline-2.6.4/egg-dist-tmp-YY0tQa
In file included from /usr/include/features.h:352,
                 from /usr/include/limits.h:27,
                 from /usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/limits.h:122,
                 from /usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/syslimits.h:7,
                 from /usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/limits.h:11,
                 from /usr/local/python2.6/include/python2.6/Python.h:19,
                 from Modules/readline.c:8:
/usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or directory
error: Setup script exited with error: command 'gcc' failed with exit status 1

The latest error is due to not having glibc-devel package for 32bit (thanks to this thread). I also had to install ncurses-devel.i386 and then easy_install went through and ipython recognized it. My life felt ruined until I got this working for the sake of ipython.

最新的错误是由于没有 32 位的 glibc-devel 包(感谢这个线程)。我还必须安装 ncurses-devel.i386,然后通过 easy_install 并且 ipython 识别出它。直到我为了 ipython 才开始工作之前,我的生活都被毁了。

bash-3.2$ CFLAGS=-m32 easy_install readline
Searching for readline
Reading http://pypi.python.org/simple/readline/
Reading http://www.python.org/
Best match: readline 2.6.4
Downloading http://pypi.python.org/packages/source/r/readline/readline-2.6.4.tar.gz#md5=7568e8b78f383443ba57c9afec6f4285
Processing readline-2.6.4.tar.gz
Running readline-2.6.4/setup.py -q bdist_egg --dist-dir /tmp/easy_install-dHly4D/readline-2.6.4/egg-dist-tmp-oIEDYl
Adding readline 2.6.4 to easy-install.pth file

Installed /home/hari/bin/python/lib/python2.6/site-packages/readline-2.6.4-py2.6-linux-x86_64.egg
Processing dependencies for readline
Finished processing dependencies for readline

回答by max29

I had the same error when trying to install a Python package, but fixed it.
The "LONG_BIT" error was:

我在尝试安装 Python 包时遇到了同样的错误,但已修复。
“LONG_BIT”错误是:

$ easy_install astropy  
/my_path/epd/epd-7.3-2-rh5-x86/include/python2.7/pyport.h:849:2: 
error: #error "LONG_BIT definition appears wrong for platform 
(bad gcc/glibc config?)." error: Setup script exited with error: 
command 'gcc' failed with exit status 1

As you are suggesting, Alex, I had to install the correct version of Python's epd to match the requirement of my machine and that of the package I wanted to install. There were parallel versions of Python running and I think this is where the confusion and error came from. Go to Enthought's Repository(click "Log in to the repository" -> Installers) and install the correct version.

正如您所建议的,亚历克斯,我必须安装正确版本的 Python epd 以匹配我的机器和我想安装的包的要求。有并行版本的 Python 正在运行,我认为这就是混淆和错误的来源。转到Enthought 的存储库(单击“登录存储库”-> 安装程序)并安装正确的版本。

Make sure you clean things up (or ask someone who knows what they are doing to do this for you) by removing the old Python versions. Then of course change your .cshrc path to point to the new version and source the file correctly. I had no problems after I did this.

确保通过删除旧的 Python 版本来清理东西(或询问知道他们在做什么的人为你做这件事)。然后当然更改您的 .cshrc 路径以指向新版本并正确获取文件。我这样做后没有任何问题。

I realize this questions was asked 4 years ago!

我意识到这个问题是 4 年前提出的!

回答by chronospoon

I actually found this thread twice, a couple years apart, both while trying to install libxml2from source. The library's configurescript actually has a --without-pythonoption, which I used instead of trying to fix the error.

我实际上在尝试libxml2从源代码安装时两次发现了这个线程,相隔几年。库的configure脚本实际上有一个--without-python选项,我使用它而不是尝试修复错误。