473,386 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

weird embedding problem

Hi all,

I'm embedding python in a C prog which is built as a linux shared lib.

The prog is linked against libpython, and on startup, it calls
Py_Initialize().

The prog imports a pure-python script. The script starts up ok, but when
it imports the 'math' module, the import fails with:

Traceback (most recent call last):
File "/home/david/work/video/myprogs/dvedit/test/frei0rfx1.py", line 10, in <module>
import math
ImportError: /usr/lib/python2.5/lib-dynload/math.so: undefined symbol: PyExc_ValueError
Failed to import math

Any ideas of how to work around this?

Please note - the program I'm writing *must* be built as a shared lib, so
the usual practice of 'extend, don't embed' is just not an option here.

Thoughts?

Cheers
D
Dec 7 '07 #1
4 2641
On Dec 7, 2:01 pm, DavidM <nos...@nowhere.comwrote:
Hi all,

I'm embedding python in a C prog which is built as a linux shared lib.

The prog is linked against libpython, and on startup, it calls
Py_Initialize().

The prog imports a pure-python script. The script starts up ok, but when
it imports the 'math' module, the import fails with:

Traceback (most recent call last):
File "/home/david/work/video/myprogs/dvedit/test/frei0rfx1.py", line 10, in <module>
import math
ImportError: /usr/lib/python2.5/lib-dynload/math.so: undefined symbol: PyExc_ValueError
Failed to import math

Any ideas of how to work around this?

Please note - the program I'm writing *must* be built as a shared lib, so
the usual practice of 'extend, don't embed' is just not an option here.

Thoughts?

Cheers
D
the math module above is failing to load because of: "undefined
symbol: PyExc_ValueError"
You may have to import some other module before loading math.
Try doing nm on libraries in /usr/lib/python2.5/lib-dynload & see
which one has this symbol (a function) in defined state ("T").

Also, verify if your script works fine out of the C program - may be
at python prompt.
Dec 7 '07 #2
On Dec 7, 5:01 pm, DavidM <nos...@nowhere.comwrote:
Hi all,

I'm embedding python in a C prog which is built as a linux shared lib.

The prog is linked against libpython, and on startup, it calls
Py_Initialize().

The prog imports a pure-python script. The script starts up ok, but when
it imports the 'math' module, the import fails with:

Traceback (most recent call last):
File "/home/david/work/video/myprogs/dvedit/test/frei0rfx1.py", line 10, in <module>
import math
ImportError: /usr/lib/python2.5/lib-dynload/math.so: undefined symbol: PyExc_ValueError
Failed to import math

Any ideas of how to work around this?

Please note - the program I'm writing *must* be built as a shared lib, so
the usual practice of 'extend, don't embed' is just not an option here.

Thoughts?
Are you actually linking your C program against the Python library?

Graham

Dec 7 '07 #3
On Fri, 07 Dec 2007 00:53:15 -0800, Graham Dumpleton wrote:
Are you actually linking your C program against the Python library?
Yes. Refer OP:
>I'm embedding python in a C prog which is built as a linux shared lib.
The prog is linked against libpython, and on startup, it calls
Py_Initialize().
Dec 7 '07 #4
On Dec 7, 11:44 pm, DavidM <nos...@nowhere.comwrote:
On Fri, 07 Dec 2007 00:53:15 -0800, Graham Dumpleton wrote:
Are you actually linking your C program against the Python library?

Yes. Refer OP:
I'm embedding python in a C prog which is built as a linux shared lib.
The prog is linked against libpython, and on startup, it calls
Py_Initialize().
What was the compiler link line you used for your program/shared
library then?

Have you confirmed using 'ldd' command that your program/shared
library do actually link against libpython?

Your original description is confusing. You say your program is built
as a shared library. Can you properly explain the full process you are
using to build your code and if you are producing a shared library for
your program how then is that shared library being used with an actual
executable? Be specific about where the program main() is located?

Some platforms don't necessarily find symbols from shared library 'A'
linked against a program executable if the main() is actually obtained
from a shared library 'B" linked to the same program and where the
symbols required from 'A' are only used in 'B'. What is required is to
link library 'A' against library 'B'.

Graham
Dec 8 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Atul Kshirsagar | last post by:
I am embedding python in my C++ application. I am using Python *2.3.2* with a C++ extention DLL in multi-threaded environment. I am using SWIG-1.3.19 to generate C++ to Python interface. Now to...
4
by: Alicia Haumann | last post by:
I accidentally sent this to webmaster@python.org, so this could be a duplicate if "webmaster" forwards it to this list. :{ Hi, there. Thanks for any help that can be offered. I've been...
2
by: Roose | last post by:
With some googling I have found these resources: http://docs.python.org/ext/win-dlls.html http://www.python.org/doc/faq/windows.html I have a large Win32/MFC/C/C++ application that has an...
7
by: Ryan Park | last post by:
Hi, //SITUATION I got a panel control that hold a certain position on a form. Every controls or UIs are on this panel. At certain situation, I called dispose() method of this panel control...
2
by: Lyn | last post by:
I am trying to embed a picture into a Bound Object Frame (Me!Photograph) with the following code which is based on MS article http://support.microsoft.com/?id=158941: strPathname =...
13
by: Krzysztof Bartosiewicz | last post by:
Hi! I have a problem with an access database. The database which I designed and made using MS access works perfectly OK on my computer however it is not working at all on computers for which it...
6
by: Qun Cao | last post by:
Hi Everyone, I am a beginner on cross language development. My problem at hand is to build a python interface for a C++ application built on top of a 3D game engine. The purpose of this python...
6
by: mistabean | last post by:
Hello, first of all, I am a programming newbie, especially in python... Onwards to the problem, I have been having difficulty embedding a python module into my C/C++ program. (just a test...
0
by: Tim Spens | last post by:
--- On Fri, 6/27/08, Tim Spens <t_spens@yahoo.comwrote: I think I know where the problem is but I'm unsure how to fix it. When I call Register_Handler(...) from python via...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.