Hallo, ich bin neu in python und habe folgendes Problem: Ich möchte in der Shell ein Modul aufrufen. Das Modul liegt in einem Ordner zB C:\matthias\my_folder_with_module Im Ordner liegt dann das *.py, welches das Modul ist. In diesem ist eine Klasse namens Vec. Folgendes habe ich ausprobiert: 1.) sys.path.append(r'C:\matthias\my_folder_with_module') und dann die folgenden Zeilen: a) from my_folder_with_module.module import Vec b) from module import Vec c) from my_folder_with_module import Vec 2.) den Pfad C:\matthias\my_folder_with_module zur Pathvariable hinzugefügt und dann auch diverse from ...import Fehlermeldungen: a) ImportError: No module named 'my_folder_with_module' b) ImportError: No module named 'module' c) ImportError: No module named 'my_folder_with_module' Hat jemand von euch ein Beispiel wie ich man das wie in zB C machen kann, dass man einfach einen Pfad angibt? Beste Grüße, Matthias
https://docs.python.org/2/tutorial/modules.html#the-module-search-path Für das import ist Variante b korrekt, sofern dein Modul in einer Datei namens module.py definiert ist: > b) from module import Vec
:
Bearbeitet durch User
Danke für die Antwort. Wenn ich die Python CMD in dem Ordner starte indem meine Module sind, dann geht es auch ohne sys.path.append(...) einfach mit Variante b) Ich habe es vorher in der shell probiert, da fand python aber wie gesagt das Modul nicht... LG
Ist im Verzeichnis C:\matthias\my_folder_with_module auch eine _init_.py (2 Unterstriche vor und nach dem init)?
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.