0

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
7
  • 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. Commented Apr 15, 2024 at 7:36
  • Appended the requested output in the question as it was too long, Commented Apr 15, 2024 at 7:46
  • Additionally when I run the script, I get the following error as well in the log: [3383862:3383942:0415/043005.777458:ERROR:ssl_client_socket_impl.cc(960)] handshake failed; returned -1, SSL error code 1, net_error -101 Commented Apr 15, 2024 at 8:31
  • "I am linking a x.so with libpython.so " how? Commented Apr 15, 2024 at 8:32
  • I am doing this via Makefile of the module x. Effectively in the log, in the command line it expands to: @=== Loading lni64/libx.so: ... g++ -shared -Wl,-Bsymbolic -m64 -pipe -fPIC -Wl,--no-undefined -O2 -ffloat-store -L /tools/python/lib -L /tools/boost/lib/64bit -lpython3.9 -lboost_python38 -o /lni64/libx.so Commented Apr 15, 2024 at 8:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.