Skip to content

Commit

Permalink
Workaround for distutils bug in Ubuntu/Debian's Python3 versions
Browse files Browse the repository at this point in the history
  • Loading branch information
ferrouswheel committed Jun 12, 2019
1 parent 74d4d40 commit f2095f8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ IF(HAVE_PY_INTERP)
# Find python destination dir for python bindings
# because it may differ on each operating system.
EXECUTE_PROCESS(
COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import *;print(get_python_lib(True, False, '${CMAKE_INSTALL_PREFIX}'))"
COMMAND ${PYTHON_EXECUTABLE} "${PROJECT_SOURCE_DIR}/scripts/get_python_lib.py" "${CMAKE_INSTALL_PREFIX}"
OUTPUT_VARIABLE PYTHON_DEST
)

Expand Down
26 changes: 26 additions & 0 deletions scripts/get_python_lib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import sys
import sysconfig
import site

if __name__ == '__main__':
# This is a hack due to the distutils in debian/ubuntu's python3 being misconfigured
# see discussion https://github.com/opencog/atomspace/issues/1782
#
# If the bug is fixed, this script could be replaced by:
#
# from distutils.sysconfig import get_python_lib; print(get_python_lib(plat_specific=True, prefix=prefix))
#
# However, using this would not respect a python virtual environments, so in a way this is better!

prefix = sys.argv[1]

# use sites if the prefix is recognized and the sites module is available
# (virtualenv is missing getsitepackages())
if hasattr(site, 'getsitepackages'):
paths = [p for p in site.getsitepackages() if p.startswith(prefix)]
if len(paths) == 1:
print(paths[0])
exit(0)

# use sysconfig platlib as the fall back
print(sysconfig.get_paths()['platlib'])

0 comments on commit f2095f8

Please sign in to comment.