Find which python modules are being imported

后端 未结 4 840
有刺的猬
有刺的猬 2021-01-31 08:16

What\'s an easy way of finding all the python modules from a particular package that are being used in an application?

4条回答
  •  旧时难觅i
    2021-01-31 08:44

    A real simple method is to delete all .pyc files from the package or folder, and then run the application. Once you've played a bit, do a directory listing and see which files have .pyc files now. Those are modules which were imported by the application.

    (Note: the __main__ module, whichever one you invoke as the "main" script, never gets compiled, so you should not expect to see a .pyc file for it unless something imported it from within the application. This is often a sign of a problem if it does happen.)

提交回复
热议问题