I am using Python 3.9 on Linux. The python installation structure looks like:
/tools/python/bin - containing python executable
/tools/python/lib/libpython3.9.so
/tools/python/lib/python3.9/lib-dynload/*
I am linking a x.so with libpython.so and trying to run it. And when I run a simple python script test.py(present in /share/python) that looks like:
import unittest
import math
class Test_2(unittest.TestCase):
def test_distance(self):
self.assertAlmostEqual(box1.distance(box2), math.sqrt(2))
def suite() :
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(Test_2))
return suite
It simply gives the following error in the log:
ImportError: Failed to import test module: test
Traceback (most recent call last):
File "/share/python/test.py", line 3, in <module>
import math
ImportError: /tools/python/lib/python3.9/lib-dynload/math.so: undefined symbol: PyFloat_Type
I have set PYTHONPATH as : /share/python and PYTHONHOME as : /tools/python And appended LD_LIBRARYPATH with /tools/python/lib so that it finds libpython3.9.so But still get the above import error: "math.so: undefined symbol: PyFloat_Type" Can someone pls help me in this issue.
Following is the output:
[abc@xyz01 ~]$ ldd /tools/python/bin/python
linux-vdso.so.1 (0x00007ffc281ce000)
libpython3.9.so.1.0 => /tools/python/lib/libpython3.9.so.1.0 (0x00007f28887d8000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007f28885af000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f288838f000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f288818b000)
libutil.so.1 => /lib64/libutil.so.1 (0x00007f2887f87000)
libm.so.6 => /lib64/libm.so.6 (0x00007f2887c05000)
libc.so.6 => /lib64/libc.so.6 (0x00007f2887840000)
/lib64/ld-linux-x86-64.so.2 (0x00007f2888b6a000)
[abc@xyz01 ~]$ echo $PYTHONPATH
/share/python
[abc@xyz01 ~]$ echo $PYTHONHOME
/tools/python
[abc@xyz01 bin]$ echo $LD_LIBRARY_PATH
tools/python/lib:/build/tools/libstdc+/lib64:/build/tools/lib/64bit:/build/tools/lib:/build81/tools/Qt/v5/64bit/lib:/build/tools/boost/lib/64bit/:/usr/lib64:/build/tools/lib/64bit/RHEL/RHEL8:/build/tools/lib/64bit/RHEL/RHEL7:/build81/tools/libstdc++/lib64:/build81/tools/lib/64bit:/usr/X11R6/lib:/lib:/usr/lib
ldd /tools/python/bin/python? Please show an output of environment (the 3 mentioned variables), command line ran and the error. How did you build your Python instance? Any errors in the logs? The error text is strange as math module is builtin for a long time.