Ich habe ein Projekt mit dieser Struktur (hier nur mit dem betroffenen) importieren:kann nicht Modul Python Import
main.py # starting script
/app
|__init__.py
|/exceptions
| __init__.py # content: from .ex400 import *
| base.py
| ex400.py # content: some classes extending classes from base.py
|/extend
| __init__.py # empty
| module.py
von /app/extend/module.py
, ich Klassen von /app/exceptions/ex400.py
zu importieren versuchen. Und aus dem Haupt importierte ich module.py
module.py
# I added this to check the path, output is below
import sys
print 'Working directory =>', sys.path
from app.exceptions.ex400 import SomeClass, MoreClass
# ... some code here ofcourse
und beim Laufen, erhalte ich ein ImportError
.
Working directory => ['/prj/myproject', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages']
...
File "/prj/myproject/app/extend/module.py", line 5, in <module>
from app.exceptions.ex400 import SomeClass, MoreClass
ImportError: No module named exceptions.ex400
Fehle ich hier etwas?
Im sorry !, ich verpasst wirklich, dass in meiner Frage, aber ich habe das hehe traurig !, krank bearbeiten – rrw
Das ist seltsam, ich Ihre Struktur neu erstellt ein es funktioniert auf meinem Rechner ... Irgendwelche Fehler könnte sein? (Alberner Vorschlag, aber weißt du) Was ist der Inhalt deines "__init __. Py" in _app_folder? Und der Inhalt von main.py? –
ist es seltsam! Ich habe wie unsere für dieses sh ** .. Ich denke nicht, Tippfehler ist die Ursache, denn wenn ich den relativen Import 'von .. exceptions.ex400 importieren Klasse 'es funktioniert .. – rrw