首页 > 编程语言 >关于module:undefined symbol:PyExc_ImportError在C语言中嵌入Python时

关于module:undefined symbol:PyExc_ImportError在C语言中嵌入Python时

时间:2023-07-19 18:24:11浏览次数:46  
标签:PyExc undefined lib ImportError python2.7 python so 链接 galaxy


cimporterrormakefilemodulepython-2.7

undefined symbol: PyExc_ImportError when embedding Python in C

 

我正在开发一个C共享库,该库可以调用python脚本。
当我运行应用程序时,出现以下错误:

1
2
3
4
5
6
7
8
9
10
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 _io
ImportError: /usr/lib/python2.7/lib-dynload/_io.so: undefined symbol: PyExc_ImportError

如果我尝试从控制台导入模块io,则可以正常工作:

1
2
3
4
5
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
[GCC 4.5.2] on linux2
Type"help","copyright","credits" or"license" for more information.
>>> import galaxy.eggs
>>>

在库的编译过程中,我按照以下建议使用了此编译器选项:
将python嵌入C中,未定义符号:PyExc_ImportError
另外,我还添加了从
python-config --includes | --libs | --cflags | --ldflags

在这里您可以找到库http://pastebin.com/348rhBjM的makefile日志

 相关讨论  

 

  • 该命令应为:pastebin.com/jSqSnBj5,在这里,您可以找到pastebin.com/348rhBjM的整个make日志。
  • 您有很多警告,您确实应该检查! 乍一看,最严重的似乎是:globus_gfs_acl_vm.c:260:33: warning: passing argument 2 of ‘snprintf’ makes integer from pointer without a cast。 尽管可能与您的问题无关,但您应该真正尝试修复尽可能多的警告!
  • @ rdil2503:请标记为接受的答案,最好是Trevors。

 

 


@ user1515248解决方案是不建议使用的仅链接解决方案。我正在编写此答案,以扩展他给出的链接,并提供更加充实的答案(这也备份了他给出的链接)。

链接https://mail.python.org/pipermail/new-bugs-announce/2008-November/003322.html表示:

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.

我要做的就是添加一行代码:

1
2
3
4
// new line of code
void*const libpython_handle = dlopen("libpython2.6.so", RTLD_LAZY | RTLD_GLOBAL);

PyInitialize();

ps。
我正在使用CentOS-6。

p.p.s.
我的PyInitialize()被包装在一个类中,因此dlopen() / PyInitialize()在构造函数中完成,而dlclose() / PyFinalize()在析构函数中完成。

 相关讨论  

 

  • 不要忘记说它必须包含在#include 中以支持dlopen和RTLD_LAZY

 

 


我找到了解决方案。也许对其他人有用。
这是python的错误,写在这里http://mail.python.org/pipermail/new-bugs-announce/2008-November/003322.html
我使用了这里发布的解决方案http://www.cilogon.org/gsi-c-authz

 相关讨论  

 

  • 第一个链接mail.python.org/pipermail/new-bugs-announce/2008-November/提供了简洁明了的问题陈述和解决方案。
  • 第二个链接cilogon.org/gsi-c-authz漫长而曲折,是为一个特定的应用程序编写的,我找不到任何看起来像通用解决方案的东西。 一定要去第一个链接

 

 


我使用这样的解决方法:从lib-dynload目录中显式链接插件(很简单,然后在代码中显式dlopen)。 datetime.so的示例:

cmake:

1 SET ( CMAKE_SHARED_LINKER_FLAGS"/usr/lib/python2.7/lib-dynload/datetime.so" )

 

 

或者只是将/usr/lib/python2.7/lib-dynload/datetime.so添加为链接器参数
命令行中的gcc:

1 g++ -shared -o libfoo.so foo.o -lbar -lzab /usr/lib/python2.7/lib-dynload/datetime.so

 

 

标签:PyExc,undefined,lib,ImportError,python2.7,python,so,链接,galaxy
From: https://www.cnblogs.com/lidabo/p/17566430.html

相关文章

  • Uncaught Error: Unsupported GeoJSON type: undefined
     渲染一个json数据(含坐标,应该就是Geojson类型)出现该错误。 AI:这表示在您的JavaScript代码中,您正在处理的GeoJSON数据存在问题。错误明确指出GeoJSON类型为undefined,这意味着您试图访问或处理的GeoJSON数据没有有效或被识别的类型  ---------------------shp文件构成--......
  • [Typescript] 150 Hard - OptionalUndefined
    Implementtheutiltype OptionalUndefined<T,Props> thatturnsallthepropertiesof T thatcanbe undefined,intooptionalproperties.Inaddition,asecond-optional-generic Props canbepassedtorestrictthepropertiesthatcanbealtered.Opti......
  • 7.null和undefined的区别
    7.null和undefined的区别?首先Undefined和Null都是基本数据类型,这两个基本数据类型分别都只有一个值,就是undefined和null。undefined代表的含义是未定义,null代表的含义是空对象。一般变量声明了但还没有定义的时候会返回undefined,null主要用于赋值给一些可能会返......
  • Python 引用问题 - ImportError: attempted relative import with no known parent pa
    问题描述近日在尝试引用其他文件的代码时,遇到了错误:ImportError:attemptedrelativeimportwithnoknownparentpackage.问题大致是这样的:我想在code2.py中引用code1.py的函数,如from..folder1.code1importxxx,运行code2.py时出现错误。root├──folder1│......
  • echarts 在使用dataZoom时报错,Cannot read properties of undefined (reading 'type')
    今天我再vue中使用柱状图拖动时,一直报错Cannotreadpropertiesofundefined(reading'type')。原因如下,我使用了myChart来接收数据,当myChart使用的是vue的ref或者reactive来命名的变量,如果这样子命名就会报上述错误。myChart=echarts.init(statistical......
  • python 导入错误 ImportError: Unable to import required dependencies: numpy
    python导入错误ImportError:Unabletoimportrequireddependencies:numpy  python3.9对应的numpy版本  参考:https://blog.csdn.net/guigenyi/article/details/126248488https://wenku.csdn.net/answer/0366fcc7857bccdefced2aaa09d7b02chttps://wenku.csdn.n......
  • ImportError:无法从“django.utils.encoding”导入名称“force text”[Python错误已解
    在软件开发过程中遇到错误是很常见的,在使用Python和Django时,这样的错误之一就是ImportError:cannotimportname'forcetext'from'django.utils.encoding'.forcetext此特定错误表明从模块导入方法时出现问题django.utils.encoding。缺少的方法用于将输入数据转换为一致......
  • react的函数式组件中使用ref获取到子组件的方法为undefined
    我暂时遇到了两种情况。第一种情况:useImperativeHandle函数写错useImperativeHandle的第二个参数的返回值是作为ref.current的值,但是我写箭头函数写快了,忘记返回值了。useImperativeHandle(ref,()=>{foo},[foo])//错误,这样没有返回值,所以ref.current为undefineduseImp......
  • 解决PetaLinux编译Microblaze的U-Boot的错误 “undefined reference to `eth_get_dev_
    错误PetaLinux编译Microblaze的U-Boot时,遇到下列错误,链接时提示找不到相关函数。|microblazeel-xilinx-linux-ld.bfd-Bstatic--no-dynamic-linker-Ttext0x80100000-ou-boot-Tu-boot.ldsarch/microblaze/cpu/start.o--start-grouparch/microblaze/cpu/built-......
  • 2023-06-25 SassError: Undefined variable: "$u-bg-color".
    前言:项目引入uview,使用uview的image组件时,报错:20:55:49.932SassError:Undefinedvariable:"$u-bg-color".20:55:49.937online255ofD:\project\mall-uni\uni_modules\uview-ui\components\u-image\u-image.vue20:55:49.938>>$u-image-error......