python - ValueError:尝试在非包内包引用中进行相对导入
问题描述
运行 main.py 时出现“ValueError: Attempted relative import in non-package”错误。下面是我的文件夹结构。请帮助我,我很困惑。另外,尝试了这篇文章https://docs.python.org/3/tutorial/modules.html “6.4.2. Intra-package References”
test(folder) which has below files
|--> __init__.py
|--> a.py
|--> b.py
|--> main.py
一个.py
def test():
print('hi')
b.py
def testing():
print('helo')
主文件
from . import a,b
a.test()
b.testing()
错误:
回溯(最近一次调用):文件“main.py”,第 1 行,来自 . import a,b ValueError: Attempted relative import in non-package
解决方案
推荐阅读
- java - 使用 zip4j 解压 zip 文件时出现“负时间”异常
- angular - 如何在角度使用resteasy正确发送文件?
- swift - Swift 4 - 垂直 UICollectionView 上的 UIRefreshControl 滞后
- c++ - Visual Studio 2008 c++ 可执行文件(调试和发布)不起作用
- android - 在 Recyclerview 顶部添加视图
- python - 放入循环时如何更新 datetime.now 函数
- ios - iOS - 如何使用 tesseract OCR 将文本识别为块
- maven - 具有自动配置的自定义 Micronaut 模块/jar
- javascript - ReactJS更改状态错误的数组项:无法分配给对象的只读属性
- java - wsdl2java 不会生成所有存根 java