2017-04-19 3 views
0

Error: ImportError: No module named common_components.modules.logging.logger passiert beim Ausführen python emailsender.py.Python: ImportError meines eigenen Moduls

Ausgang:

(dev) [email protected]:~/workspace/python/python/common_components/modules/email$ python emailsender.py 
Traceback (most recent call last): 
    File "emailsender.py", line 23, in <module> 
    from common_components.modules.logging.logger import Log 
ImportError: No module named common_components.modules.logging.logger 

Nicht sicher, ob etwas nicht in Ordnung mit der folgenden Projektstruktur:

(dev) [email protected]:~/workspace/python/python$ tree 
. 
├── common_components 
│   ├── __init__.py 
│   ├── modules 
│   │   ├── email 
│   │   │   ├── emailsender.py 
│   │   │   └── __init__.py 
│   │   ├── __init__.py 
│   │   ├── logging 
│   │   │   ├── __init__.py 
│   │   │   └── logger.py 
└── __init__.py 

eine Idee? Dank

UPDATE

(dev) [email protected]:~/workspace/python$ python python/common_components/modules/email/emailsender.py 
Traceback (most recent call last): 
    File "python/common_components/modules/email/emailsender.py", line 23, in <module> 
    from common_components.modules.logging.logger import Log 
ImportError: No module named common_components.modules.logging.logger 
(dev) [email protected]:~/workspace/python$ cd python/ 
(dev) [email protected]:~/workspace/python/python$ python common_components/modules/email/emailsender.py 
Traceback (most recent call last): 
    File "common_components/modules/email/emailsender.py", line 23, in <module> 
    from common_components.modules.logging.logger import Log 
ImportError: No module named common_components.modules.logging.logger 
+1

'common_components' ist nicht in Ihrem Python-Pfad. Der einfachste Weg, dies zu lösen, besteht darin, das Skript von '.' mit' python common_components/modules/email/emailsender.py' auszuführen. Das Arbeitsverzeichnis befindet sich immer im Python-Pfad. –

+0

Ihr 'python'-Verzeichnis enthält '__init __. Py'. Ich bin mir nicht sicher, ob das einen Unterschied macht, aber es scheint komisch, da ich mir vorstelle, dass du nicht vorhast, dass es ein Paket ist. –

Antwort

0

Python fügt das aktuelle Verzeichnis zu dem PYTHONPATH, aber Ihr aktuelles Verzeichnis ist ~/workspace/python/python/common_components/modules/email.

Fix dies entweder durch von ~/workspace/python/python/ ausgeführt wird:

[email protected]:~/workspace/python/python$ python common_components/modules/email/emailsender.py 

Oder durch PYTHONPATH manuelle Einstellung:

[email protected]:~/$ set PYTHONPATH=~/workspace/python/python/ 

[email protected]:~/workspace/python/python/common_components/modules/email$ python emailsender.py 
+0

Danke. Aber nicht funktioniert. Mein Beitrag wurde aktualisiert. Danke – BAE

+0

Sie müssen aus dem 'workspace/python/python'-Verzeichnis ausführen, damit es das' common_components' Paket finden kann. Sie führen von 'workspace/python' aus, das das' python'-Verzeichnis enthält, nicht 'common_components'. –

+0

Versucht. funktioniert nicht. verdrahtet. – BAE

Verwandte Themen