Ich arbeite an einem Flask -Projekt, in dem ich eine Paketstruktur wie folgt verwende: < /p>
Code: Select all
twitter_post_enhancer/
├── app/
│ ├── __init__.py
│ ├── routes.py
│ └── utils/
├── run.py
< /code>
Aber wenn ich die App mit: < /p>
ausführepython run.py
< /code>
Ich erhalte diesen Fehler: < /p>
ImportError: attempted relative import with no known parent package
< /code>
Auswechsel von App.Routes importieren Sie Haupt < /code> - Funktionen, aber VS -Code zeigt nicht erledigt. Änderung. Imports < /strong> (für Modularität) < /li>
Führen Sie das Projekt mit Python Run.py < /code> Aus dem Root < /li>
VS Code /Pylanzimportfehler (wie "unreale Import") < /li>
< /ul>
< /> < /> < /> < /ul>
< /> < /ul>
Führen Sie aus. Kontext):
https://github.com/chitranshu0/twitter-post-enhancer
Was ist das cleanste und das. />
Relative Importe wie aus .Routes importieren Sie Haupt < /code> richtig arbeiten < /li>
Die App läuft aus dem Lauf.