I have problem with importing package in python module. That's what I do:
from mega.mega import Mega
if __name__ == "__main__":
m = Mega()
and from java I run:
interpreter.execfile("api.py");
But I still get error:
Exception in thread "main" Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named mega
In mega folder I have mega.py file and __init__.py
file to mark this folder as package.
Now I get:
from mega.mega import Mega
SyntaxError: ("'import *' not allowed with 'from .'", ...path...
You'll need to add the parent directory of mega
to 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__
is the filename of the api.py
module (can be relative).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.