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.

classification
Title: Python3.7 places cwd instead of a scripts path in sys.path.
Type: security Stage: resolved
Components: Versions: Python 3.7
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: AndreasPK, ericvw, methane
Priority: normal Keywords:

Created on 2018-07-12 15:06 by AndreasPK, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg321563 - (view) Author: AndreasPK (AndreasPK) Date: 2018-07-12 15:06
Andi@Horzube MINGW64 ~/tmp
$ python3.7 ../pyTest.py
['', 'C:/ghc/msys64/mingw64/lib/python37.zip', 'C:/ghc/msys64/home/Andi/tmp', 'C:/ghc/msys64/mingw64/lib/python3.7', 'C:/ghc/msys64/mingw64/bin', 'C:/ghc/msys64/mingw64/lib/python3.7/lib-dynload', 'C:/ghc/msys64/mingw64/lib/python3.7/site-packages']

Andi@Horzube MINGW64 ~/tmp
$ python3.6 ../pyTest.py
['/home/Andi', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/usr/lib/python3.6/site-packages']

Ignore the path prefix differences, they comes from slight differences how I installed these two versions.

3.6 lists '/home/Andi', path of the script
3.7 lists /home/Andi/tmp , path of cwd

This breaks existing code looking for files (imports primarily) relative to a scripts path.
If a file is placed in the right relative path to cwd it will be picked up over the intended file.

This should be at least mentioned in breaking changes.
msg321569 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2018-07-12 16:44
inada-n@rinrin:~/t$ ../pyenv/versions/3.7.0/bin/python ../fset.py
['/home/inada-n', '/home/inada-n/pyenv/versions/3.7.0/lib/python37.zip', '/home/inada-n/pyenv/versions/3.7.0/lib/python3.7', '/home/inada-n/pyenv/versions/3.7.0/lib/python3.7/lib-dynload', '/home/inada-n/.local/lib/python3.7/site-packages', '/home/inada-n/pyenv/versions/3.7.0/lib/python3.7/site-packages']

inada-n@rinrin:~/t$ ../pyenv/versions/3.6.5/bin/python ../fset.py
['/home/inada-n', '/home/inada-n/pyenv/versions/3.6.5/lib/python36.zip', '/home/inada-n/pyenv/versions/3.6.5/lib/python3.6', '/home/inada-n/pyenv/versions/3.6.5/lib/python3.6/lib-dynload', '/home/inada-n/pyenv/versions/3.6.5/lib/python3.6/site-packages']

Both 3.6 and 3.7 use script directory, not cwd.

I don't know what's wrong on your environment.
Your Python 3.6 and 3.7 are build by exactly same way except prefix?
msg321571 - (view) Author: AndreasPK (AndreasPK) Date: 2018-07-12 17:37
Thank you for the fast response!

Both versions are distributed via msys I did not build them myself and installed 3.7 via pacman (today).

$ python3.7
Python 3.7.0 (default, Jul 12 2018, 11:44:33)  [GCC 7.3.0 64 bit (AMD64)] on win32

I only found out about this issue after someone else complained that GHC's testsuite was broken with 3.7. After upgrading mine it broke for me as well and we narrowed it down to this issue.

I've tested the version from python.org in a windows shell as well which works so I can confirm your results there.
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

I've also tried running the version from python.org but in the msys shell which also works.

So it seems to be an issue with the version distributed by msys!
I'm not familiar with the details of how msys composes their packages. (If they distribute an official build, build their own or what not).

But this seems related: https://github.com/Alexpux/MINGW-packages/issues/4062
I will link this thread there and hope this leads somewhere.
msg321572 - (view) Author: AndreasPK (AndreasPK) Date: 2018-07-12 17:51
I've learned that msys builds their own Python binary which is the one broken. So I'm closing this as it's my undestanding that it is not a bug in the official distribution.

Thanks for the quick responses.
History
Date User Action Args
2022-04-11 14:59:03adminsetgithub: 78284
2018-07-12 17:51:53AndreasPKsetstatus: open -> closed

messages: + msg321572
stage: resolved
2018-07-12 17:37:13AndreasPKsetmessages: + msg321571
2018-07-12 16:44:32methanesetnosy: + methane
messages: + msg321569
2018-07-12 16:32:09ericvwsetnosy: + ericvw
2018-07-12 15:06:11AndreasPKcreate