@theinfmonkey: Damit ein Package-Import funktioniert, müssen es natürlich auch Packages sein. Schau mal in der Dokumentation wie man aus einem Verzeichnis ein Package macht.
Dazu muss doch nur eine __init__.py in dem Verzeichnis liegen, oder? Das ist bei mir der Fall.
Nochmal mein Verzeichnis, vielleicht ist es ja dann besser zu verstehen:
/home/mario/workspace/fwtrace/src/tools/echo.py
/home/mario/workspace/fwtrace/src/tools/__init__.py
/home/mario/workspace/fwtrace/src/main/test.py
/home/mario/workspace/fwtrace/src/main/__init__.py
Alle Dateien:
Code: Alles auswählen
#/home/mario/workspace/fwtrace/src/tools/echo.py
def areYouThere():
return "I am here."
Code: Alles auswählen
#/home/mario/workspace/fwtrace/src/main/test.py
import sys, os
sys.path.append(sys.path[0].rsplit("/", 1)[0])
print "sys.path:", sys.path[-1]
import tools.echo as echo
print "Are you there?", echo.areYouThere()
Beide __init__.py sind vorhanden und leer.
Wenn ich test.py jetzt mit Eclipse ausführe erhalte ich
Code: Alles auswählen
sys.path /home/mario/workspace/fwtrace/src
Are you there? I am here.
Den gleichen Code auf einer Konsole:
Code: Alles auswählen
mario@mario-laptop:~/workspace/fwtrace/src/main$ python test.py
sys.path: /home/mario/workspace/fwtrace/src
Are you there? I am here.

Und auf einmal funktioniert es... und mir ist immer noch nicht wirklich klar, was jetzt anders ist.
Danke erstmal für die Hilfe.
Anfänger.