0
Sorry für dumme Frage. Ich habe diese Dateien:Kann immer noch nicht verstehen, Python-Import
a\
|-__init__.py
|-b\
|---__init__.py
|---c.py
c.py enthält Klasse 'd'.
Diese Form funktioniert:
>>> import a.b.c as c
>>> from a import b
Diese Formulare funktionieren nicht:
>>> from a.b import c
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'c'
cannot import name 'c'
>>> from a.b.c import d
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'a.b.c'
No module named 'a.b.c'
- Wenn
from a import b
funktioniert, warumfrom a.b import c
einen Fehler wirft? - Wenn
import a.b.c
funktioniert, warum gibtfrom a.b import c
einen Fehler aus? Wenn'd' from 'c'
funktioniert, warum gibtfrom a.b.c import d
einen Fehler aus?
Alle Ihre "gebrochenen" Beispiele funktionieren auf meinen Python 2.7 und 3.4 Systemen. –
Ich stimme dem zu, was John sagte, aber nur um zu überprüfen: Laufen Sie konsequent von der Wurzel Ihres Projekts aus (das heißt, ist ein Unterverzeichnis des Arbeitsverzeichnisses, im Gegensatz zu von innen läuft) – Foon