module include path - /usr/local/lib/python3 vs /usr/local/lib/python3.9

Mats Wichmann mats at wichmann.us
Thu Jun 17 14:22:24 EDT 2021


On 6/17/21 1:53 AM, Joachim Wuttke wrote:
> How to write a platform-independent CMake install command
> to install a Swig-generated Python module?
> 
> The following brings us very close to a solution:
> ```
> execute_process(
>      COMMAND "${Python3_EXECUTABLE}"
>      -c "from distutils import sysconfig as sc;
>          print(sc.get_python_lib(prefix='', plat_specific=True))"
>      OUTPUT_VARIABLE PYTHON_SITE
>      OUTPUT_STRIP_TRAILING_WHITESPACE)
> message(STATUS "Python module libcerf will be installed to ${PYTHON_SITE}")
> 
> install(FILES ${CMAKE_CURRENT_BINARY_DIR}/<our_module>.py
>          DESTINATION ${PYTHON_SITE})
> ```
> 
> So far, we only tested under Debain, where the problem arises:
> 
> - distutils.sysconfig.get_python_lib(...) returns lib/python3/dist-packages
> - CMake provides CMAKE_INSTALL_PREFIX=/usr/local/
> - So installation goes to /usr/local/lib/python3/dist-packages
> - sys.path, however, does not contain /usr/local/lib/python3/dist-packages.
> 
> sys.path contains /usr/local/lib/python3.9/dist-packages, and also
> /usr/lib/python3/dist-packages, so this is slightly incoherent.
> Anyway, we won't want to change sys.path. So we need to change
> the above CMake/Python code to return a local installation directory
> that is part of sys.path.
> 
> Thanks for any hints - Joachim

dist-packages is Debian-family-specific anyway, other Linux distros 
don't use it - and some have some interesting conventions - if you're 
using Swig to build a binary extension module, it needs to go in a 
lib-dynload directory on Fedora.

You should look at the Python sysconfig module in preference to using 
the one from distutils.

You probably need to say more about what the target is - are you 
attempting to install as part of the process building a distro package, 
or are you expecting to install directly?


More information about the Python-list mailing list