Python 3.10运行时警告

iklwldmw  于 4个月前  发布在  Python
关注(0)|答案(1)|浏览(86)

我的Python版本是3.10.12,我的项目的某些部分具有以下结构:

shapy/
    ...
    regressor/
        ...
        human_shape/
             ...
             data/
                 ...
                 datasets/
                     ...
                     openpose.py
                     __init__.py
                 structures/
                     ...
                     keypoints.py
                     __init__.py
                 __init__.py
             __init__.py

字符串
我想运行openpose.py,所以我使用regressor文件夹中的命令:

python -m human_shape.data.datasets.openpose


然后我得到了一个错误:

/usr/lib/python3.10/runpy.py:126: RuntimeWarning: 'human_shape.data.datasets.openpose' found in sys.modules after import of package 'human_shape.data.datasets', but prior to execution of 'human_shape.data.datasets.openpose'; this may result in unpredictable behaviour
  warn(RuntimeWarning(msg))


我知道这个问题表明在导入human_shape.data.datasets.openpose模块之前已经在sys.modules中找到了human_shape.data.datasets包,但我已经尝试检查sys.modules,没有相关的包。
如何解决此问题?

yi0zb3m4

yi0zb3m41#

尝试使用绝对导入。
在openpose.py文件的开头添加以下代码,以打印sys.modules的内容。这可以帮助您识别导入包的位置。

import sys
print(sys.modules)

字符串
同时确保在你的代码中没有循环导入,因为它们会导致不可预知的行为。当两个或多个模块相互依赖时,循环导入就会发生。

相关问题