Seite 1 von 1

Module

Verfasst: Donnerstag 18. April 2019, 22:28
von 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

Re: Module

Verfasst: Freitag 19. April 2019, 00:18
von __blackjack__
@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

Re: Module

Verfasst: Freitag 19. April 2019, 10:25
von anonym110
Vielen Dank für die schnell Antwort - hat sehr geholfen.