get_python_lib() returns path to python3 instead of python3.6

Bug #1814653 reported by Alexander
28
This bug affects 5 people
Affects Status Importance Assigned to Milestone
python3-defaults (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

Python version is Python 3.6.7 (default, Oct 22 2018, 11:32:17)
Ubuntu 18.04.01

When I call get_python_lib() function to get the Python lib path to install a module it returns '/usr/lib/python3/dist-packages' instead of python3.6 dir:
python3 -c "from distutils.sysconfig import *;print(get_python_lib())"

This is because the source code '/usr/lib/python3.6/distutils/sysconfig.py' has the branch on Ubuntu:

Code:
------------
    if os.name == "posix":
        libpython = os.path.join(prefix,
                                 "lib", "python" + get_python_version())
        if standard_lib:
            return libpython
        elif (is_default_prefix and
              'PYTHONUSERBASE' not in os.environ and
              'VIRTUAL_ENV' not in os.environ and
              'real_prefix' not in sys.__dict__ and
              sys.prefix == sys.base_prefix):
            return os.path.join(prefix, "lib", "python3", "dist-packages")
------------

However, this code does not present in the original cpython code 3.6.7:
https://github.com/python/cpython/blob/ca7d2933a388677cc3bbc621913b479452c0f25a/Lib/distutils/sysconfig.py#L109

Is it the right behavior?

Why the get_python_lib() result should depend on PYTHONUSERBASE and VIRTUAL_ENV and points to python3 instead of python3.6

ProblemType: Bug
DistroRelease: Ubuntu 18.04
Package: python3 3.6.7-1~18.04
ProcVersionSignature: Ubuntu 4.15.0-44.47-generic 4.15.18
Uname: Linux 4.15.0-44-generic x86_64
ApportVersion: 2.20.9-0ubuntu7.3
Architecture: amd64
CurrentDesktop: ubuntu:GNOME
Date: Tue Feb 5 12:41:28 2019
InstallationDate: Installed on 2018-09-06 (151 days ago)
InstallationMedia: Ubuntu 18.04 LTS "Bionic Beaver" - Release amd64 (20180426)
SourcePackage: python3-defaults
UpgradeStatus: No upgrade log present (probably fresh install)

Revision history for this message
Alexander (stellarspot) wrote :
Revision history for this message
Launchpad Janitor (janitor) wrote :

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

Changed in python3-defaults (Ubuntu):
status: New → Confirmed
Revision history for this message
vital (vsbogd) wrote :

The issue is that if `get_python_lib()` is called with `prefix='/usr/local'` argument then Ubuntu version returns:
``` sh
$ /usr/bin/python3 -c "from distutils.sysconfig import *;print(get_python_lib(prefix='/usr/local'))"
/usr/local/lib/python3/dist-packages
```

while mainstream Python returns:
```sh
$ python3 -c "from distutils.sysconfig import *;print(get_python_lib(prefix='/usr/local'))"
/usr/local/lib/python3.6/site-packages
```

`sys.path` (in both Ubuntu and mainstream Python) doesn't contain `/usr/local/lib/python3/dist-packages` path, it contains `/usr/local/lib/python3.6/dist-packages` instead, so when `/usr/local` prefix is used things don't work:
```
$ PYTHONPATH='' /usr/bin/python3 -c "import sys; print(sys.path)"
['', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/home/vital/.local/lib/python3.6/site-packages', '/usr/local/lib/python3.6/dist-packages', '/usr/lib/python3/dist-packages']
```

Revision history for this message
vital (vsbogd) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.