0

In debugging some module issues, I would like to have insight into what exactly happens when I run import google (or any import modules).

  • Was it loaded or did it come from cache?
  • Where did it get imported from? (its not always from a file - it is possible to create a module and add it into the namespace directly)
  • What loader was used?
  • What about anything that was imported during the import?

Is there a way to get diagnostics on this?

3
  • 1
    Does this answer your question? Trace Python imports Commented May 7, 2021 at 20:13
  • @mkrieger1 its good to know for sure and is helpful, I upvoted it, but that only gives some of the info I mentioned. For example in my case in a venv with google sdk import google logs nothing because it is a builtin but it is not in sys.builtin_module_names so where is it coming from? It wasn't in the namespace previously so import did do something. More to the point, importing a module that I think should be on my sys.path is not finding it, so I want to know what it tried Commented May 7, 2021 at 20:21
  • digging into the specific issue more, it seems to have something to do with the site module which is automatically loaded. Omitting it with -S doesn't preload that stuff Commented May 9, 2021 at 20:54

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.