找不到Python自定义模块,但已经存在 [英] Python custom module not found but already exists
本文介绍了找不到Python自定义模块,但已经存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个单独的文件来容纳我的Python文件的一些自定义问题类,并在执行以下命令后执行:coverage run test_syntax.py
它会打印出以下错误,如
I have created a separate file to hold some custom issue classes for my Python file and upon execution of the following command: coverage run test_syntax.py
it prints out the following error as seen in this Travis CI build:
Traceback (most recent call last):
File "test_syntax.py", line 9, in
from ros import main as s
File "/home/travis/build/Richienb/ROS-Code/src/ros/main.py", line 57, in
from errors import ConversionError, WrongInput, UnexpectedError
ModuleNotFoundError: No module named 'errors'
您可以在此处
此外,我已经进入src
目录.
Also, I have already cd into the src
directory.
推荐答案
您需要这样的相对导入(在我的计算机上需要第二次导入才能达到您发布的错误):
You need a relative import like this (second one was needed on my machine to even get to the error you have posted):
# in main.py
from .errors import ...
# ros.py
from . import errors
这篇关于找不到Python自定义模块,但已经存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文