Python - 导入错误 : No module named foo. 栏

标签 python importerror python-import

>>> from foo.bar import app
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named foo.bar

我的目录结构:

In /foo:
    __init__.py
    bar.py

In /foo/tests:
    __init__.py
    testing.py

/foo/tests/testing.py 中,我需要从 /foo/bar.py 导入应用程序。如果运行testing.py 文件,我会收到ImportError

我已检查 sys.path 并包含 /foo/foo/tests 文件夹。

最佳答案

sys.path 应包含 foo 的父目录,而不是 foo 本身

关于Python - 导入错误 : No module named foo. 栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12698834/

相关文章:

python - ValueError : Invalid\escape: error while doing json. 加载()

c# - IronPython 导入异常 : No module named logging

python - 如何解决ImportError : libhdf5_serial. so.103: cannot open shared object file: No such file or directory while Importing h5py

python - 在 python 解释器中 Hook 全局名称查找

python - 使另一个模块可以从我的 Python 模块中导入

python - Pandas 基于两个现有变量创建一个新变量

python - 尝试将 Pyinstaller 与 Pandas 一起使用时,出现意外的 EOF 错误。我不知道是什么原因造成的

python - 使用 Selenium Webdriver 检测是否发送了 WhatsApp 消息

unit-testing - 如何在 vue-test-utils 和 jest 中使用动态导入测试组件

python - 导入时是否有退出模块的命令,例如返回函数