Struktur Programm
│ ├── common
│ │ ├── __init__.py
│ │ ├── modul1.py
│ │ ├── modul2.py
│ │ └── modul3.py
│ └── tests
│ ├── __init__.py
│ ├── test_modul1.py
│ ├── test_modul2.py
│ └── test_modul3.py
common/__init__.py:
__all__ = ['module1','modul2','modul3']
tests/__init__.py:
__all__ = [test_modul1','test_modul2','test_modul3']
tests/test_modul1.py:
from common.modul1 import func_modul1_1
func_modul1_1()
Fehlermeldung
headhunter1978:omission-git headhunter1978$ /usr/local/bin/python3 "/Users/headhunter1978/Library/Mobile Documents/com~apple~CloudDocs/omission-git/omission/tests/test_modul1.py"
Traceback (most recent call last):
File "/Users/headhunter1978/Library/Mobile Documents/com~apple~CloudDocs/omission-git/omission/tests/test_modul1.py", line 1, in <module>
from common.modul1 import func_modul1_1
ModuleNotFoundError: No module named 'common'
Ich möchte von tests/test_modul1.py auf common/test_modul1.py zu greifen. Unter pyCharm funktioniert das. Wenn ich das unter Visual Studio Code ausführe, bekomme ich folgende Meldung:
ModuleNotFoundError: No module named 'common'
Habt ihr eine Idee, was ich falsch mache?
Zugriff auf Package im Subfolder
- __blackjack__
- User
- Beiträge: 14322
- Registriert: Samstag 2. Juni 2018, 10:21
- Wohnort: 127.0.0.1
- Kontaktdaten:
Damit das funktioniert muss das Arbeitsverzeichnis das Verzeichnis sein in dem `common/` und `tests/` liegen.
„Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.“ — Brian W. Kernighan
-
headhunter1978
- User
- Beiträge: 20
- Registriert: Sonntag 18. November 2018, 11:15
Beide Verzeichnisse liegen im Arbeitsverzeichnis. Wie gesagt, das komische ist, dass es unter Pycharm läuft aber unter VSC nicht.
