Open nbigaouette opened 4 years ago
--enable-shared
may also cause problems with python>=3.3
.
package distributors like https://packages.debian.org/en/sid/libpython3-dev , they don't consider python's patch version, or may not provide the newest library.
I installed python=3.8.1
with hygeia
, and I got error messages like this:
$ python3 python3: error while loading shared libraries: libpython3.8.so.1.0: cannot open shared object file: No such file or directory Error: Failed to execute command (exit code: Some(127)): python3
so I installed libpython=3.8
, but got libpython3.8.0
, so python3 -V
showed version 3.8.0
.
Which distro are you using? Debian, Ubuntu? And which version?
When compiling on Linux I use LD_RUN_PATH
to encode the path to the shared libraries inside the built binary. This way python should pick up its own shared library when run. See: https://github.com/nbigaouette/hygeia/blob/a19d29927573cedcf616ac40e82dd5d59ae55e47/src/commands/install/unix.rs#L151-L155
It seems that if you have a shared library installed system wide it is picked up first.
Can you try to call python directly using LD_LIBRARY_PATH
and see what happens? The binary should pick up its own library.
LD_LIBRARY_PATH=${HYGEIA_HOME}/installed/cpython/3.8.1/lib ${HYGEIA_HOME}/installed/cpython/3.8.1/bin/python -V
If that works I'll try to think of something...
I'm having trouble reproducing your problem.
I'm using docker to get a debian sid (sid-20191224
) environment. This one comes with Python 3.7.6:
hygeia@2d18f7390b85:~$ hygeia list
+--------+---------+---------------------+--------------------------------------------------+
| Active | Version | Installed by hygeia | Location |
+--------+---------+---------------------+--------------------------------------------------+
| | 3.7.6 | | /usr/bin |
+--------+---------+---------------------+--------------------------------------------------+
hygeia@2d18f7390b85:~$ /usr/bin/python3 -V
Python 3.7.6
The binary is not dynamically link to libpython:
hygeia@2d18f7390b85:~$ ldd /usr/bin/python3
linux-vdso.so.1 (0x00007ffdb396a000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6c46eee000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f6c46ecd000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f6c46ec8000)
libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007f6c46ec3000)
libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f6c46e96000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f6c46e79000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f6c46d32000)
/lib64/ld-linux-x86-64.so.2 (0x00007f6c470b4000)
hygeia@2d18f7390b85:~$ /usr/bin/python3 -m sysconfig -c 'print(sysconfig.get_config_vars())' | grep -i shared
BLDSHARED = "x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro"
CCSHARED = "-fPIC"
CFLAGSFORSHARED = "-fPIC"
CONFIG_ARGS = "'--enable-shared' '--prefix=/usr' '--enable-ipv6' '--enable-loadable-sqlite-extensions' '--with-dbmliborder=bdb:gdbm' '--with-computed-gotos' '--without-ensurepip' '--with-system-expat' '--with-system-libmpdec' '--with-system-ffi' 'CC=x86_64-linux-gnu-gcc' 'CFLAGS=-g -fstack-protector-strong -Wformat -Werror=format-security ' 'LDFLAGS= -Wl,-z,relro' 'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2'"
COVERAGE_INFO = "/build/python3.7-9TOSzB/python3.7-3.7.6/build-shared/coverage.info"
COVERAGE_REPORT = "/build/python3.7-9TOSzB/python3.7-3.7.6/build-shared/lcov-report"
DESTSHARED = "/usr/lib/python3.7/lib-dynload"
INSTALL_SHARED = "/usr/bin/install -c -m 555"
LDCXXSHARED = "x86_64-linux-gnu-g++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions"
LDSHARED = "x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro"
LINKFORSHARED = "-Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions"
Py_ENABLE_SHARED = "1"
RUNSHARED = "LD_LIBRARY_PATH=/build/python3.7-9TOSzB/python3.7-3.7.6/build-shared"
TESTPYTHON = "LD_LIBRARY_PATH=/build/python3.7-9TOSzB/python3.7-3.7.6/build-shared ./python"
TESTRUNNER = "LD_LIBRARY_PATH=/build/python3.7-9TOSzB/python3.7-3.7.6/build-shared ./python ../Tools/scripts/run_tests.py"
abs_builddir = "/build/python3.7-9TOSzB/python3.7-3.7.6/build-shared"
abs_srcdir = "/build/python3.7-9TOSzB/python3.7-3.7.6/build-shared/.."
Installing 3.8.1 succeeds:
hygeia@2d18f7390b85:~$ hygeia list
+--------+---------+---------------------+--------------------------------------------------+
| Active | Version | Installed by hygeia | Location |
+--------+---------+---------------------+--------------------------------------------------+
| | 3.8.1 | ✓ | /home/hygeia/.hygeia/installed/cpython/3.8.1/bin |
+--------+---------+---------------------+--------------------------------------------------+
| | 3.7.6 | | /usr/bin |
+--------+---------+---------------------+--------------------------------------------------+
hygeia@2d18f7390b85:~$ ldd /home/hygeia/.hygeia/installed/cpython/3.8.1/bin/python
linux-vdso.so.1 (0x00007ffcb74e1000)
libpython3.8.so.1.0 => /home/hygeia/.hygeia/installed/cpython/3.8.1/lib/libpython3.8.so.1.0 (0x00007fa2dda23000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa2dd85f000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fa2dd83e000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fa2dd839000)
libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007fa2dd834000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fa2dd6ef000)
/lib64/ld-linux-x86-64.so.2 (0x00007fa2ddda7000)
hygeia@2d18f7390b85:~$ /home/hygeia/.hygeia/installed/cpython/3.8.1/bin/python -m sysconfig -c 'print(sysconfig.get_config_vars())' | grep -i shared
BLDSHARED = "gcc -pthread -shared"
CCSHARED = "-fPIC"
CFLAGSFORSHARED = "-fPIC"
CONFIG_ARGS = "'--prefix' '/home/hygeia/.hygeia/installed/cpython/3.8.1' '--enable-shared' 'CFLAGS=' 'LDFLAGS=' 'CPPFLAGS='"
DESTSHARED = "/home/hygeia/.hygeia/installed/cpython/3.8.1/lib/python3.8/lib-dynload"
INSTALL_SHARED = "/usr/bin/install -c -m 755"
LDCXXSHARED = "g++ -pthread -shared"
LDSHARED = "gcc -pthread -shared"
LINKFORSHARED = "-Xlinker -export-dynamic"
Py_ENABLE_SHARED = "1"
RUNSHARED = "LD_LIBRARY_PATH=/home/hygeia/.hygeia/cache/extracted/Python-3.8.1"
hygeia@2d18f7390b85:~$ /home/hygeia/.hygeia/installed/cpython/3.8.1/bin/python -V
Python 3.8.1
Running python3 -m sysconfig -c 'print(sysconfig.get_config_vars())'
might reveal what is wrong...
http://blog.dscpl.com.au/2015/06/installing-custom-python-version-into.html explains why distro provided python is statically linked but still include a shared lib; TL;DR the toolchain is compiled twice, once with configure --enable-shared
and once with make altbininstall
... 🤔
There two issues here:
--enable-shared
so hygeia
simply doesn't use --enable-shared
for <3.3.0. I'm not sure if this is "fixable", those versions might just be too old for compiling on more modern system... This issue is about keeping track of that problem.I've opened #139 to track the separate issue.
If
--enable-shared
is used to compile Python <3.3.0, linking fails but is hard to see directly in pycors as it simply hangs:pstree
shows the calling hierarchy:Instead, running this manually exposes the linking problem (on macOS Catalina):