New submission from James Saryerwinnie <j...@jamesls.com>:
There was a change in behavior in Python 3.8.10 when using relative paths in sys.path. It appears that the paths are now converted to absolute paths that are cached and can cause import errors in some cases. Repro: $ cat repro.sh #!/bin/bash python --version mkdir -p /tmp/repro/{A,B}/testproject echo "msg = 'from A'" > /tmp/repro/A/testproject/app.py echo "msg = 'from B'" > /tmp/repro/B/testproject/app.py python -c " import sys, os, shutil os.chdir('/tmp/repro/A') sys.path.append('testproject') import app print(app) print(app.msg) os.chdir('/tmp/repro/B') shutil.rmtree('/tmp/repro/A') del sys.modules['app'] import app print(app) print(app.msg) " rm -rf /tmp/repro On Python 3.8.9 I get: $ ./repro.sh Python 3.8.9 <module 'app' from 'testproject/app.py'> from A <module 'app' from 'testproject/app.py'> from B On Python 3.8.10 I get: $ ./repro.sh Python 3.8.10 <module 'app' from '/private/tmp/repro/A/testproject/app.py'> from A Traceback (most recent call last): File "<string>", line 12, in <module> ModuleNotFoundError: No module named 'app' I haven't confirmed this (I can't work out the frozen bootstrap stuff), but this might be caused by https://bugs.python.org/issue43105, whose patch does seem to be converting paths to absolute paths. ---------- components: Library (Lib) messages: 393212 nosy: James.Saryerwinnie priority: normal severity: normal status: open title: Regression with relative paths in sys.path in python 3.8.10 type: behavior versions: Python 3.10, Python 3.11, Python 3.8, Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue44070> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com