简体   繁体   English

ImportError:当包含___init__.py时,没有名为test的模块

[英]ImportError: No module named test when ___init__.py is included

I created a python project in this format: 我以这种格式创建了一个python项目:

在此处输入图片说明

I tried to run my test_jabba.py by cd ing into the tests directory and running the program and I received this error: 我试图运行我的test_jabba.py通过cd荷兰国际集团到tests目录并运行该程序,我收到此错误:

Traceback (most recent call last):
  File "./test_jabba.py", line 12, in <module>
    from tests import testbench
ImportError: No module named tests

I read around and I realized I needed __init__.py to tell python where other packages are located. 我四处阅读,意识到我需要__init__.py来告诉python其他包在哪里。

Top portion of test_jabba.py test_jabba.py

from tests import testbench
from utils import gopher, jsonstream

I did not add __init__.py into my logs and resources directories as they do no contain any python. 我没有将__init__.py添加到我的logsresources目录中,因为它们不包含任何python。

My best guess would be that poc is not in your PYTHONPATH . 我最好的猜测是poc不在您的PYTHONPATH You can either set/extend the environment variable to contain poc , or you can manipulate the path in your script using os.path . 您可以将环境变量设置/扩展为包含poc也可以使用os.path在脚本中操作路径 Your imports, in this case, will have to change accordingly: 在这种情况下,您的进口商品将必须进行相应的更改:

from poc.tests import testbench
from poc.utils import gopher, jsonstream

Alternatively, you can use a relative import, to import tests and utils : 另外,您也可以使用相对导入,导入testsutils

from ..tests import testbench
from ..utils import gopher, jsonstream

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ImportError:__init__.py文件中没有名为…的模块 - ImportError: No module named… in __init__.py file Python3错误“ImportError:没有名为的模块”有__init__.py - Python3 error “ImportError: No module named” have __init__.py ImportError:没有名为…的模块(但是我有__init__.py文件并设置了PYTHONPATH) - ImportError: No module named … (but I have __init__.py files and have set PYTHONPATH) ImportError:在__init__.py文件Python中导入类时没有名为''的模块 - ImportError: No module named ' ' while Import class in the __init__.py file Python ImportError __init__.py,烧瓶 - ImportError __init__.py, flask ImportError:DLL加载失败:加载__init__.py时找不到指定的模块 - ImportError: DLL load failed: The specified module could not be found when loading __init__.py 何时在模块中执行__init__.py? - When is __init__.py in a module executed? 模块中的函数的ModuleNotFoundError已包含在__init__.py文件中 - ModuleNotFoundError for function in module that's been included in __init__.py file ImportError:没有名为ex47.game的模块(是的,我有一个__init__.py文件*并且*我尝试了所有PYTHONPATH的东西 - ImportError: No module named ex47.game (and yes, I have an __init__.py file *AND* I tried all that PYTHONPATH stuff 接收导入错误:没有名为***的模块,但有__init__.py - Receiving Import Error: No Module named ***, but has __init__.py
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM