我有一个文件调用entryPoint.py:
from .commonLib.deviceLib import *
Run Code Online (Sandbox Code Playgroud)
我有一个名为deviceLib.py:
import math
import sys
import logging
import requests
import this
class DeviceLib(object):
def __init__(self, connectionDb):
self.__db = connectionDb
Run Code Online (Sandbox Code Playgroud)
树是这样的:
/test
entryPoint.py
/commonLib
__init__.py
deviceLib.py
Run Code Online (Sandbox Code Playgroud)
当我执行时,python entryPoint.py我收到错误:Attempted relative import in non-package。请帮我。
ewa*_*lel 10
使用sys.path.append附加您的 python 文件(模块所在的目录)。例如,如果您的entryPoint.py在地址目录中
import sys
sys.path.append('/path/to/your/module/address/')
import entryPoint
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18121 次 |
| 最近记录: |