What exactly does ./configure --enable-shared do during python altinstall?

前端 未结 3 843
感动是毒
感动是毒 2021-01-31 11:24

When I altinstall python 2.7.12 with

./configure --prefix=/opt/python --enable-shared

it comes up as python 2.7.5 (system default python

相关标签:
3条回答
  • 2021-01-31 11:26

    With ldd comand you can view where the executable is searching for libraries:

    ldd python2.7
        linux-vdso.so.1 =>  (0x00007fffa75ec000)
        libpython2.7.so.1.0 => /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 (0x00007f717042e000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f7170211000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f716fe46000)
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f716fc2c000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f716fa28000)
        libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007f716f824000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f716f51b000)
        /lib64/ld-linux-x86-64.so.2 (0x000055969d00b000)enter code here
    

    You can change the lib search path of python2.7 setting LD_LIBRARY_PATH variable in the environment (non-persistent):

    export LD_LIBRARY_PATH=/opt/python/lib
    

    or setting a persistant system-wide way:

    echo "/opt/python/lib" > /etc/ld.so.conf.d/python.conf
    ldconfig -v
    

    or setting a persistent executable way:

    patchelf --set-rpath /opt/python/lib/ python2.7
    
    0 讨论(0)
  • 2021-01-31 11:40

    Compiling python like this fixed my issue:

    ./configure --enable-shared --prefix=/opt/python LDFLAGS=-Wl,-rpath=/opt/python/lib
    

    Courtesy Ned Deily:

    The problem is, that on most Unix systems (with the notable exception of Mac OS X), the path to shared libraries is not an absolute path. So, if you install Python in a non-standard location, which is the right thing to do so as not to interfere with a system Python of the same version, you will need to configure in the path to the shared library or supply it via an environment variable at run time, like LD_LIBRARY_PATH. You may be better off avoiding --enable-shared; it's easy to run into problems like this with it.

    Ref: https://bugs.python.org/issue27685

    0 讨论(0)
  • 2021-01-31 11:44

    I'm not sure why the version number is different, but Graham Dumpleton says at this website that "When running configure, you should be supplying the --enable-shared option to ensure that shared libraries are built for Python. By not doing this you are preventing any application which wants to use Python as an embedded environment from working."

    0 讨论(0)
提交回复
热议问题