0

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?

10
  • 2
    site is not a builtin module Commented Nov 16, 2015 at 14:18
  • Actually it is: docs.python.org/2/library/site.html However, my python behaves as described in the docs Commented Nov 16, 2015 at 14:19
  • Where in that doc do you see that it should be a builtin? A builtin module (like for example sys) does not have a .py file, site does come from site.py. Commented Nov 16, 2015 at 14:20
  • I have another machine running Python 2.7.3 however, and there Python behaves as described. I.e. it doesn't matter whether I have a site.py in the CWD or not, it's always imported from '/usr/lib/python2.7/site.pyc' Commented Nov 16, 2015 at 14:20
  • 1
    @karlson - is your PYTHONPATH set? site seems to be imported before the CWD is added to sys.path, but the PYTHONPATH env variable is added earlier if set. Commented Nov 16, 2015 at 14:46

1 Answer 1

2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.