This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: wrong default module search path in help message
Type: behavior Stage: resolved
Components: Versions: Python 3.7, Python 3.6, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: christian.heimes Nosy List: christian.heimes, eric.snow, eryksun, gauravbackback, steve.dower, vstinner, xiang.zhang, zach.ware
Priority: normal Keywords: easy, patch

Created on 2017-09-13 08:01 by xiang.zhang, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 3624 merged gauravbackback, 2017-09-17 06:10
PR 4613 merged python-dev, 2017-11-28 15:17
Messages (9)
msg302032 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2017-09-13 08:01
In python --help:

PYTHONHOME   : alternate <prefix> directory (or <prefix>:<exec_prefix>).
               The default module search path uses <prefix>/pythonX.X.

I think the default module search path should be <prefix>/lib/pythonX.X.
msg302338 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2017-09-16 13:48
You are right, the path is wrong on Unix-like platforms. It's os.path.join(sys.prefix, 'lib', 'python{major}.{minor}'). But the actual path may depend on the platform, too. I don't recall how Windows sets up the path.
msg302339 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2017-09-16 13:51
See site module, especially site._get_path()

# Same to sysconfig.get_path('purelib','_user')
def _get_path(userbase):
    version = sys.version_info

    if == 'nt':
        return f'{userbase}\\Python{version[0]}{version[1]}\\site-packages'

    if sys.platform == 'darwin' and sys._framework:
        return f'{userbase}/lib/python/site-packages'

    return f'{userbase}/lib/python{version[0]}.{version[1]}/site-packages'
msg302361 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2017-09-17 08:05
Not sure about Windows. _get_path() looks to me is used for user site-packages. getsitepackages() doesn't do the same and seems matching the current message, also the OS2 branch in py2. Let's consult Windows guys.
msg302480 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2017-09-18 18:50
I don't have time right this second to write it all up, but I did so in the past at

Hopefully the answer you need is somewhere in that. Module search paths are complicated (but eric.snow is going to make it possible to use Python code to derive the search path at startup... right Eric? Right? :) )
msg307127 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2017-11-28 15:16
New changeset 08d2b86a1058b733bb7f1ae2b55818dd9687d21c by Christian Heimes (gauravbackback) in branch 'master':
bpo-31440: Changed default module search path for windows
msg307132 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-11-28 15:45
I confirm that Python 2.7 is affected and should also be fixed.
msg307147 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2017-11-28 17:18
I'll do a backport tomorrow.
msg307148 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2017-11-28 17:18
New changeset cb79c2203953bd465f2c53b7a09a51071717575f by Christian Heimes (Miss Islington (bot)) in branch '3.6':
bpo-31440: Changed default module search path for windows (#4613)
Date User Action Args
2022-04-11 14:58:52adminsetgithub: 75621
2018-12-27 23:36:34cheryl.sabellasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2017-11-28 17:18:31christian.heimessetmessages: + msg307148
2017-11-28 17:18:05christian.heimessetassignee: christian.heimes
messages: + msg307147
2017-11-28 15:45:16vstinnersetnosy: + vstinner
messages: + msg307132
2017-11-28 15:17:42python-devsetpull_requests: + pull_request4528
2017-11-28 15:16:33christian.heimessetmessages: + msg307127
2017-09-18 18:50:00steve.dowersetnosy: + eric.snow
messages: + msg302480
2017-09-17 08:05:45xiang.zhangsetnosy: + zach.ware, eryksun, steve.dower, gauravbackback
messages: + msg302361
2017-09-17 06:10:04gauravbackbacksetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request3614
2017-09-16 13:51:15christian.heimessetmessages: + msg302339
2017-09-16 13:48:11christian.heimessettype: behavior

messages: + msg302338
nosy: + christian.heimes
2017-09-13 08:01:11xiang.zhangcreate