[New-bugs-announce] [issue33689] Blank lines in .pth file cause a duplicate sys.path entry

Malcolm Smith report at bugs.python.org
Tue May 29 19:03:14 EDT 2018


New submission from Malcolm Smith <malcolm.smith at gmail.com>:

The `site` module documentation says that in .pth files, "Blank lines and lines beginning with # are skipped.". However, the implementation does not actually skip blank lines. It then joins the empty string to the site-packages directory, resulting in the site-packages directory being added to sys.path a second time.

Example:

$ python -c 'import sys; print(sys.path)'
['', '/home/smith/.virtualenvs/foo/lib/python36.zip', '/home/smith/.virtualenvs/foo/lib/python3.6', '/home/smith/.virtualenvs/foo/lib/python3.6/lib-dynload', '/usr/lib/python3.6', '/home/smith/.virtualenvs/foo/lib/python3.6/site-packages']
$ echo > /home/smith/.virtualenvs/foo/lib/python3.6/site-packages/test.pth
$ python -c 'import sys; print(sys.path)'
['', '/home/smith/.virtualenvs/foo/lib/python36.zip', '/home/smith/.virtualenvs/foo/lib/python3.6', '/home/smith/.virtualenvs/foo/lib/python3.6/lib-dynload', '/usr/lib/python3.6', '/home/smith/.virtualenvs/foo/lib/python3.6/site-packages', '/home/smith/.virtualenvs/foo/lib/python3.6/site-packages']

A patch fixing this is attached to issue 29326, but was ignored when that issue turned out to be caused by something else.

----------
components: Library (Lib)
messages: 318137
nosy: Malcolm Smith
priority: normal
severity: normal
status: open
title: Blank lines in .pth file cause a duplicate sys.path entry
type: behavior
versions: Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33689>
_______________________________________


More information about the New-bugs-announce mailing list