跟踪Python导入
发布于 2021-01-29 19:24:17
我的Python库刚刚将其主模块名称从更改foo.bar
为foobar
。对于向后兼容,foo.bar
仍然存在,但是将其导入会引发一些警告。现在,似乎仍然有一些示例程序从旧模块导入,但不是直接导入。
我想找到错误的import
陈述。有没有什么工具可以让我跟踪导入并找到罪魁祸首而无需费力看所有代码?
关注者
0
被浏览
40
1 个回答
-
使用以下命令启动python解释器
-v
:$ python -v -m /usr/lib/python2.6/timeit.py # installing zipimport hook import zipimport # builtin # installed zipimport hook # /usr/lib/python2.6/site.pyc matches /usr/lib/python2.6/site.py import site # precompiled from /usr/lib/python2.6/site.pyc # /usr/lib/python2.6/os.pyc matches /usr/lib/python2.6/os.py import os # precompiled from /usr/lib/python2.6/os.pyc import errno # builtin import posix # builtin # /usr/lib/python2.6/posixpath.pyc matches /usr/lib/python2.6/posixpath.py import posixpath # precompiled from /usr/lib/python2.6/posixpath.pyc # /usr/lib/python2.6/stat.pyc matches /usr/lib/python2.6/stat.py import stat # precompiled from /usr/lib/python2.6/stat.pyc # /usr/lib/python2.6/genericpath.pyc matches /usr/lib/python2.6/genericpath.py import genericpath # precompiled from /usr/lib/python2.6/genericpath.pyc # /usr/lib/python2.6/warnings.pyc matches /usr/lib/python2.6/warnings.py import warnings # precompiled from /usr/lib/python2.6/warnings.pyc # /usr/lib/python2.6/linecache.pyc matches /usr/lib/python2.6/linecache.py import linecache # precompiled from /usr/lib/python2.6/linecache.pyc # /usr/lib/python2.6/types.pyc matches /usr/lib/python2.6/types.py import types # precompiled from /usr/lib/python2.6/types.pyc # /usr/lib/python2.6/UserDict.pyc matches /usr/lib/python2.6/UserDict.py ...
然后只是grep您的旧模块。