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?

George Mauer
  • 117,483
  • 131
  • 382
  • 612
  • 1
    Does this answer your question? [Trace Python imports](https://stackoverflow.com/questions/7332299/trace-python-imports) – mkrieger1 May 07 '21 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 – George Mauer May 07 '21 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 – George Mauer May 09 '21 at 20:54

0 Answers0