非常感谢,对您的帮助将不胜感激.解决方案 @ user1515248解决方案是仅链接的解决方案受到不利.我正在编写此答案,以扩展他给出的链接,并提供更加充实的答案(这也备份了他给出的链接).链接 https://mail.python .org/pipermail/new-bugs-announce/2008-November/003322.html ,说: 已为我提供以下解决方法:在mylib.c中,之前 PyInitialize()我可以打电话给dlopen("libpython2.5.so", RTLD_LAZY | RTLD_GLOBAL); 这可行,但是我相信lib-dynload/*.so应该取决于 libpython2.5.so.1,因此无需进行此破解. 我正在将Ubuntu 8.04与Python版本2.5.2-2ubuntu4.1结合使用.我要做的就是添加一行代码:// new line of codevoid*const libpython_handle = dlopen("libpython2.6.so", RTLD_LAZY | RTLD_GLOBAL);PyInitialize(); p.s.我正在使用CentOS-6. p.p.s.我的PyInitialize()被包装在一个类中,因此dlopen()/PyInitialize()在构造函数中完成,而dlclose()/PyFinalize()在析构函数中完成.I'm developing a C shared library that makes a call to a python script.When I run the application I get this error:Traceback (most recent call last): File "/home/ubuntu/galaxy-es/lib/galaxy/earthsystem/gridftp_security/gridftp_acl_plugin.py", line 2, in <module> import galaxy.eggs File "/home/ubuntu/galaxy-es/lib/galaxy/eggs/__init__.py", line 5, in <module> import os, sys, shutil, glob, urllib, urllib2, ConfigParser, HTMLParser, zipimport, zipfile File "/usr/lib/python2.7/zipfile.py", line 6, in <module> import io File "/usr/lib/python2.7/io.py", line 60, in <module> import _ioImportError: /usr/lib/python2.7/lib-dynload/_io.so: undefined symbol: PyExc_ImportErrorIf I try to import the module io from console works fine instead:Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)[GCC 4.5.2] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import galaxy.eggs>>>During the compilation of library I've used this compiler option as suggest here :Embedding python in C, undefined symbol: PyExc_ImportErrorIn addition I've added also the compiler options obtained frompython-config --includes|--libs|--cflags|--ldflagsHere you can find the log of makefile of library http://pastebin.com/348rhBjMThanks a lot, any help will be apreciated. 解决方案 @user1515248 solution is a link-only solution which are discouraged. i am writing this answer to expand on the links he gave and provide a more fleshed out answer (that also backs up the link he gave).The link, https://mail.python.org/pipermail/new-bugs-announce/2008-November/003322.html, says: I have been given the following workaround: in mylib.c, before PyInitialize() I can call dlopen("libpython2.5.so", RTLD_LAZY | RTLD_GLOBAL); This works, but I believe that lib-dynload/*.so should depend on libpython2.5.so.1 so this hack should not be necessary. I am using Ubuntu 8.04 with Python version 2.5.2-2ubuntu4.1.All I had to do was add a single line of code:// new line of codevoid*const libpython_handle = dlopen("libpython2.6.so", RTLD_LAZY | RTLD_GLOBAL);PyInitialize();p.s.I am on CentOS-6.p.p.s.My PyInitialize() is wrapped in a class and so dlopen()/PyInitialize() is done in the constructor and dlclose()/PyFinalize() is done in the destructor. 这篇关于未定义符号:在C中嵌入Python时出现PyExc_ImportError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-05 10:43
查看更多