The documentation for Python 2.7.10 states that
When a module named spam is imported, the interpreter first searches for a built-in module with that name. If not found, it then searches for a file named spam.py in a list of directories given by the variable sys.path
However this happens when I have a file site.py in my CWD:
import site
print(site.__file__)
>>> site.py
So obviously site was not identified as a builtin-module first, but imported from the CWD instead. Any ideas as to what might be wrong there?
Tomasz Jakub Rup
10.7k7 gold badges52 silver badges49 bronze badges
asked Nov 16, 2015 at 14:11
karlson
5,4633 gold badges33 silver badges63 bronze badges
1 Answer 1
Are you sure site is built-in module?
import sys
sys.builtin_module_names
should give you built-in modules.
Sign up to request clarification or add additional context in comments.
Comments
lang-py
siteis not a builtin modulesys) does not have a.pyfile,sitedoes come fromsite.py.site.pyin the CWD or not, it's always imported from'/usr/lib/python2.7/site.pyc'PYTHONPATHset?siteseems to be imported before the CWD is added tosys.path, but thePYTHONPATHenv variable is added earlier if set.