Author jamesls
Recipients jamesls
Date 2021-05-07.19:59:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1620417589.1.0.903069874446.issue44070@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2021-05-07 19:59:49jameslssetrecipients: + jamesls
2021-05-07 19:59:49jameslssetmessageid: <1620417589.1.0.903069874446.issue44070@roundup.psfhosted.org>
2021-05-07 19:59:49jameslslinkissue44070 messages
2021-05-07 19:59:49jameslscreate