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.

Author vstinner
Recipients brett.cannon, vstinner
Date 2016-01-18.09:12:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Example of the bug:

$ cat Lib/
import xxx

haypo@smithers$ ./python -q -c pass

The line "after" is not executed and *no* error nor warning is raised. With the patch:

$ ./python -q -c pass
Error in sitecustomize; set PYTHONVERBOSE for traceback:
ImportError: No module named 'xxx'

$ PYTHONVERBOSE=1 ./python -q -c pass
# /home/haypo/prog/python/3.5/Lib/__pycache__/sitecustomize.cpython-35.pyc matches /home/haypo/prog/python/3.5/Lib/
# code object from '/home/haypo/prog/python/3.5/Lib/__pycache__/sitecustomize.cpython-35.pyc'
Traceback (most recent call last):
  File "/home/haypo/prog/python/3.5/Lib/", line 508, in execsitecustomize
    import sitecustomize
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 662, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/haypo/prog/python/3.5/Lib/", line 2, in <module>
    import xxx
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
ImportError: No module named 'xxx'
# destroy sitecustomize

Brett Cannon: "This is a change in semantics."

Can you please elaborate? Even if importing sitecustomize changes, Python continue its execution. Only a warning is emited.

Brett Cannon: "It might be better to log an ImportWarning when the import fails and keep the current semantics (and be careful about importing warnings)."

With my patch, a message "Error in sitecustomize; set PYTHONVERBOSE for traceback:" is logged. I used the same behaviour then the code to handle site import.

Note: I found this issue when I worked on the PEP 511 to register a code transformer at startup. The bug is really annoying: the code transformers may or may not be registered depending if required modules can be important, I expect an error (or at least a warning).
Date User Action Args
2016-01-18 09:12:29vstinnersetrecipients: + vstinner, brett.cannon
2016-01-18 09:12:29vstinnersetmessageid: <>
2016-01-18 09:12:29vstinnerlinkissue26099 messages
2016-01-18 09:12:28vstinnercreate