Opened 2 years ago

Closed 7 months ago

Last modified 7 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

Description

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:

get_python_lib(prefix='/usr/local')

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 setup.py 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 setup.py call so to make the bogus destination path appear first, and I guess the --prefix switch to setup.py 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\"))"

/usr/local/lib/python3/dist-packages

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)"

['',
 '/usr/lib/python35.zip',
 '/usr/lib/python3.5',
 '/usr/lib/python3.5/plat-x86_64-linux-gnu',
 '/usr/lib/python3.5/lib-dynload',
 '~/.local/lib/python3.5/site-packages',
 '/usr/local/lib/python3.5/dist-packages',
 '/usr/lib/python3/dist-packages']

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\"))"

/usr/local/lib/python3.5/site-packages

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

comment:2 Changed 7 months ago by Even Rouault

Resolution: fixed
Status: newclosed

In 41527:

Fix python 3.x package installation in custom prefixes (patch by cwalv, fixes https://github.com/OSGeo/gdal/pull/302, fixes #6671)

comment:3 Changed 7 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 https://github.com/OSGeo/gdal/pull/302, refs #6671)

Note: See TracTickets for help on using tickets.