Opened 2 years ago

Closed 10 months ago

Last modified 10 months ago

#6671 closed defect (fixed)

Wrong installation directory for python (3.4+) extension

Reported by: strk Owned by: warmerdam
Priority: normal Milestone:
Component: default Version: unspecified
Severity: normal Keywords:
Cc: antonio, Mike Toews


The default build, with python-3.5, installs the extension in a wrong directory, that is a directory not contained in the default PYTHONPATH.

I found this being due to the way swig/python/GNUmakefile tries to determine the destination directory, which is via:


Which starting from python-3.4 seems to give an answer which is _not_ in the default PYTHONPATH (basically omits the minor version from the python directory name).

I confirm that using

python install --prefix=/usr/local

would do the right thing, both for /usr/local prefix and for other custom prefixes (on Ubuntu 16.04).

But the GNUmakefile is tweaking the PYTHONPATH prior to the call so to make the bogus destination path appear first, and I guess the --prefix switch to call simply picks the first path with the given prefix in PYTHONPATH, if present.

The use of the now-bogus get_python_lib was introduced in r30564 to fix #4563 -- I'd ask mwtoews to please test the bug he reported initially with a cleaned up GNUmakefile, and Antonio too, if possible.

Change History (3)

comment:1 Changed 2 years ago by antonio

It seems to be issue relater to the ubuntu/debian customization of the python installation. I can confirm that if I run

$ env PYTHONPATH=/opt/custompath python3 -c "from __future__ import print_function;from distutils.sysconfig import get_python_lib;print(get_python_lib(prefix=\"/usr/local\"))"


I get the path with the minor version omitted on ubuntu 10.06.

It is not in the system path

env PYTHONPATH="" python3 -c "from __future__ import print_function;import sys;print(sys.path)"


Anyway on the same machine if I use the anaconda installation I get the expected standard path:

$ env PYTHONPATH=/opt/ppp ~/anaconda3/bin/python3 -c "from __future__ import print_function;from distutils.sysconfig import get_python_lib;print(get_python_lib(prefix=\"/usr/local\"))"


Maybe it good be a good idea to contact debian developers for clarifications.

comment:2 Changed 10 months ago by Even Rouault

Resolution: fixed
Status: newclosed

In 41527:

Fix python 3.x package installation in custom prefixes (patch by cwalv, fixes, fixes #6671)

comment:3 Changed 10 months ago by Even Rouault

In 41537:

Python bindings: ammend r41527 such that prefix variable from GDALmake.opt is honoured, unless PREFIX environment variable is defined (refs, refs #6671)

Note: See TracTickets for help on using tickets.