我在python模块中导入包时遇到了问题。我就是这么做的:
from mega.mega import Mega
if __name__ == "__main__":
m = Mega()在java中我运行:
interpreter.execfile("api.py");但我还是会犯错:
Exception in thread "main" Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named mega在mega文件夹中,我有mega.py文件和__init__.py文件将该文件夹标记为包。
现在我明白了:
from mega.mega import Mega
SyntaxError: ("'import *' not allowed with 'from .'", ...path...发布于 2013-03-20 15:35:38
您需要将mega的父目录添加到sys.path
import sys
import os
PATH = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, PATH)
from mega.mega import Mega__file__是api.py模块的文件名(可以是相对的)。
https://stackoverflow.com/questions/15527950
复制相似问题