Module

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
anonym110

Hallo,

ich arbeite gerade an einem Projekt und versuche ihm eine sinnvolle Struktur zu geben. Aktuell sieht die Struktur so aus:

Code: Alles auswählen

.
├── Pipfile
├── Pipfile.lock
└── demo
    ├── demo
    │   ├── __init__.py
    │   ├── __main__.py
    │   ├── __pycache__
    │   │   └── __main__.cpython-37.pyc
    │   ├── config.py
    │   ├── module1.py
    │   └── module2.py
    └── tests
        ├── __main__.py
        ├── test1.py
        ├── test2.py
        └── testdata.py
Wenn ich nun versuche das Projekt auszuführen bekomme ich die folgende Fehlermeldung:

Code: Alles auswählen

$ pwd
.../Demo/demo
$python demo
Traceback (most recent call last):
  File "…Versions/3.7/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "…Versions/3.7/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "demo/__main__.py", line 2, in <module>
    from .module1 import demo_function1
ImportError: attempted relative import with no known parent package
Ich habe schon versucht zu recherchieren was mein Fehler ist - habe aber nichts gefunden. Würde mich freuen wenn mir jemand helfen könnte.

Hier gibt es das Projekt als download: https://filebin.net/j3b578u9856iv8cb/De ... t=nkhk4k7k

Jnnk
Benutzeravatar
__blackjack__
User
Beiträge: 13103
Registriert: Samstag 2. Juni 2018, 10:21
Wohnort: 127.0.0.1
Kontaktdaten:

@Jnnk: Das geht mit der `-m`-Option:

Code: Alles auswählen

bj@s8n:~/src/Demo/demo$ python3 -m demo
Usage: __main__.py [OPTIONS] COMMAND [ARGS]...

  DEMO command

Options:
  --help  Show this message and exit.

Commands:
  demo-function1
  demo-function2
  hello
„All religions are the same: religion is basically guilt, with different holidays.” — Cathy Ladman
anonym110

Vielen Dank für die schnell Antwort - hat sehr geholfen.
Antworten