• Willkommen im Linux Club - dem deutschsprachigen Supportforum für GNU/Linux. Registriere dich kostenlos, um alle Inhalte zu sehen und Fragen zu stellen.

python import

hallo,

ich kenne mich leider mit python nicht aus. ich moechte jetzt ein programm starten (bcfg2) und die fehlermeldung ist:
Code:
ImportError: No module named Bcfg2.Options
Bcfg2.Options gibt es auch als Datei nicht. Dafür gibt es eine Datei Options in einem Ordner Bcfg2. Ich nahm an das das die korrekte Syntax für python importe wäre über "." ein Verzeichnis zu kennzeichnen.
 
Da vermutest Du richtig. In dem Ordner muss aber noch ein __init__.py oder soähnlich drin liegen. Sonst wird der Ordner nicht als Modulordner gewertet.
 
Code:
rechner01:/usr/lib64/python2.4/site-packages/Bcfg2 # ls
Client  Logging.py  Logging.pyc  Options.py  Options.pyc  __init__.py  __init__.pyc

ich bilde mir ein genau die selben schritte auf einem anderen rechner vollzogen zu haben, auf dem dieser fehler nicht auftritt.
 
okay, was das problem "gelöst" hat, obwohl ich mich frage warum das nötig war:
Code:
ln -s /usr/lib64/python2.4/site-packages/Bcfg2 /usr/local/lib/python2.4/site-packages/Bcfg2

auf dem rechner, auf dem es ohne probleme funktioniert, existiert der link jedenfalls nicht.
 
endor schrieb:
okay, was das problem "gelöst" hat, obwohl ich mich frage warum das nötig war:
Code:
ln -s /usr/lib64/python2.4/site-packages/Bcfg2 /usr/local/lib/python2.4/site-packages/Bcfg2

auf dem rechner, auf dem es ohne probleme funktioniert, existiert der link jedenfalls nicht.

das ist auch nicht nötig ..

hättest du mal in meinem link nachgelesen, hättest du das gefunden:
6.1.1 The Module Search Path
When a module named spam is imported, the interpreter searches for a file named spam.py in the current directory, and then in the list of directories specified by the environment variable PYTHONPATH. This has the same syntax as the shell variable PATH, that is, a list of directory names. When PYTHONPATH is not set, or when the file is not found there, the search continues in an installation-dependent default path; on Unix, this is usually .:/usr/local/lib/python.

Actually, modules are searched in the list of directories given by the variable sys.path which is initialized from the directory containing the input script (or the current directory), PYTHONPATH and the installation-dependent default. This allows Python programs that know what they're doing to modify or replace the module search path. Note that because the directory containing the script being run is on the search path, it is important that the script not have the same name as a standard module, or Python will attempt to load the script as a module when that module is imported. This will generally be an error. See section 6.2, ``Standard Modules,'' for more information.
 
welchen teil davon meinst du? ich hab naemlich die beiden absaetze gelesen. daher auch der link. ich hatte es auch ueber pythonpath versucht. das hatte nicht funktioniert. oder meinst du den teil mit dem standard modul namen?
 
Ist ja schon gelöst, aber Du mußt nur in .../site-packages/
eine Datei mit Endung .pth anlegen, in der lediglich der Name des Verzeichnisses für das Modul steht, damit Python das Modul auch finden kann.
Guck mal in .../site-packages/, da müßten zahlreiche solcher .pth-Dateien sein.

Jetzt besser verständlich ?

Viele Grüße
 
Ja, in /usr/lib/python2.4/site-packages existiert schon eine .pth Datei. Dementsprechend hab ich die Verlinkung aus /usr/local/... entfernt und in /usr/lib/... neu erstellt. Dann eine pth Datei in de site-packages Ordner erstellt, und das funktioniert jetzt auch.
Ist mir dennoch nicht klar wieso er es nicht gleich in /usr/lib/.. installiert sondern in /usr/lib64/.. . Könnte es daran liegen das da mehrere Versionen von Python installiert wurden?
 
Oben