首页 > 解决方案 > “ModuleNotFoundError: No module named”但给出了正确的路径

问题描述

经典错误,尽我所能。

我想workers-python/workers/composite_key/compositekey/tests/test.pyworkers-python-framework/workers_manager/pwmf/pipeline/utils.py.

错误发生在test.py

from workers-python-framework.workers_manager.pwmf.pipeline.utils import local_mode

utils.py“本地模式”:

local_mode = ModeDefinition(
    name='local',
    resource_defs={
        's3': s3_resource,
        'tempfile': tempfile_resource,
        'file_cache': fs_file_cache,
        'file_manager': local_file_manager,
        'mds_store': mds_store,
        'fqdn_string': fqdn_string,
    },
    executor_defs=default_executors + [dask_executor],
    system_storage_defs=s3_plus_default_storage_defs,
)

但是,正确的路径和拼写存在...

me@PF2DCSXD:/mnt/c/Users/user/Documents/GitHub/workers-python-framework/workers_manager/pwmf/pipeline$ ls
utils.py

是什么导致了这个错误?我该如何解决?

终端:

me@PF2DCSXD:/mnt/c/Users/user/Documents/GitHub/workers-python/workers/composite_key/compositekey/tests$ pytest -s test_composite_key.py 
========================================================================================== test session starts ==========================================================================================platform linux -- Python 3.8.10, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
rootdir: /mnt/c/Users/user/Documents/GitHub/workers-python/workers/composite_key/compositekey, configfile: pytest.ini
collected 0 items / 1 error

================================================================================================ ERRORS =================================================================================================_____________________________________________________________________________ ERROR collecting tests/test_composite_key.py ______________________________________________________________________________ImportError while importing test module '/mnt/c/Users/user/Documents/GitHub/workers-python/workers/composite_key/compositekey/tests/test_composite_key.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.8/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
test_composite_key.py:11: in <module>
    from pwmf.pipeline.utils import local_mode
E   ModuleNotFoundError: No module named 'pwmf'
======================================================================================== short test summary info ========================================================================================ERROR test_composite_key.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!=========================================================================================== 1 error in 1.20s ============================================================================================

pwmf是一个单独的克隆 git 项目,我在项目的配置文件中引用了它。

poetry.lock

[[package]]
name = "pwmf"
version = "0.1.2.15"
description = "Python Worker Management Framework."
category = "main"
optional = false
python-versions = ">=3.7,<4.0"

pyproject.toml

pwmf = "^0.1.2.4"

如果还有什么我可以添加到帖子中,请告诉我。

标签: python-3.xpython-import

解决方案


推荐阅读