If python package is installed under get_python_lib(prefix='/usr/local') it cannot be imported by python

Bug #1832215 reported by vital
This bug affects 7 people
Affects Status Importance Assigned to Milestone
python3-stdlib-extensions (Ubuntu)

Bug Description

When `get_python_lib` function is called with `/usr/local` prefix it returns path which is not included into `sys.path` list. Consequently if python package is installed under this path it cannot be imported by python.

Path which is returned:
$ /usr/bin/python3 -c "from distutils.sysconfig import *;print(get_python_lib(prefix='/usr/local'))"

`usr/local/path` which is present in `sys.path`
$ /usr/bin/python3 -c "import sys; print('\n'.join(sys.path))" | fgrep '/usr/local'

There is the same bug reported to the `python3` package (https://bugs.launchpad.net/ubuntu/+source/python3-defaults/+bug/1814653) I created this report to stick it to the correct package.

1) The release of Ubuntu

$ lsb_release -rd
Description: Ubuntu 18.04.2 LTS
Release: 18.04

2) The version of the package

$ apt-cache policy python3-distutils
  Installed: 3.6.7-1~18.04
  Candidate: 3.6.7-1~18.04
  Version table:
 *** 3.6.7-1~18.04 500
        500 http://ru.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages
        500 http://ru.archive.ubuntu.com/ubuntu bionic-updates/main i386 Packages
        100 /var/lib/dpkg/status
     3.6.5-3 500
        500 http://ru.archive.ubuntu.com/ubuntu bionic/main amd64 Packages
        500 http://ru.archive.ubuntu.com/ubuntu bionic/main i386 Packages

3) What you expected to happen

Path returned by `get_python_lib(prefix='/usr/local')` call is present in `sys.path` list.

4) What happened instead

`get_python_lib(prefix='/usr/local')` returns /usr/local/lib/python3/dist-packages which is absent in `sys.path`

Tags: patch
Revision history for this message
vital (vsbogd) wrote :

The root cause is the Debian patch: https://salsa.debian.org/cpython-team/python3-stdlib/blob/master/debian/patches/3.6/distutils-install-layout.diff

The patch changes behavior of the `get_python_lib` for two paths '/usr' and '/usr/local', see: https://salsa.debian.org/cpython-team/python3-stdlib/blob/master/debian/patches/3.7/distutils-install-layout.diff
Lines 144 and 152-157.

I would suggest remove '/usr/local' from the line 144 to fix.

Revision history for this message
vital (vsbogd) wrote :

Attaching patch for an issue

Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

The attachment "1832215.patch" seems to be a patch. If it isn't, please remove the "patch" flag from the attachment, remove the "patch" tag, and if you are a member of the ~ubuntu-reviewers, unsubscribe the team.

[This is an automated message performed by a Launchpad user owned by ~brian-murray, for any issues please contact him.]

tags: added: patch
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in python3-stdlib-extensions (Ubuntu):
status: New → Confirmed
Revision history for this message
Matthijs (matthijsburgh) wrote :

I experience the same problem with python 3.5 on Xenial.

Revision history for this message
dimi (dbogdanov) wrote :

Still an issue on Python 3.10 on Ubuntu 22.04.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers