我有一个文件调用entryPoint.py
:
from .commonLib.deviceLib import *
我有一个名为deviceLib.py
的文件:
import math
import sys
import logging
import requests
import this
class DeviceLib(object):
def __init__(self, connectionDb):
self.__db = connectionDb
这棵树是这样的:
/test
entryPoint.py
/commonLib
__init__.py
deviceLib.py
当我执行python entryPoint.py
时,得到错误:Attempted relative import in non-package
。请帮帮我。
使用sys.path.append附加python文件(模块)所在的目录。E、 g如果您的entryPoint.py位于地址目录中
要从其他目录导入文件,可以使用以下代码:
正如您在这里看到的,我们包含了路径,因此python也将在该路径中查找文件。
/test和/commonLib reside文件夹中都应该有
__init__.py
。那就做吧
例如
假设您现在在format subrecory中打开了wavread.py,只需
更多信息, https://www.python-course.eu/python3_packages.php
相关问题 更多 >
编程相关推荐