ModuleNotFoundError: No Module Named '…' [Python]

后端 未结 2 1272
傲寒
傲寒 2021-01-27 10:27

I have only written stand alone script before in Python. Now I am trying to write an app which can transform and migrate data between two databases. But when I am trying to crea

相关标签:
2条回答
  • 2021-01-27 10:36

    What you need to do is put main.py hand over your other scripts.

    Project
         - PQF
            - db
                - __init__.py
                - DataSource.py
                - RecordSet.py
            - main.py
            - __init__.py
    

    In your main.py, you now make your imports

    0 讨论(0)
  • 2021-01-27 10:52

    Here's the full code including the __init__.py

    File - db/__init__.py

    from .DataSource import *
    from .RecordSet import * 
    

    File - main/__init__.py

    from .main import *
    

    File - PQF/__init__.py

    from .db import *
    from .main import *
    
    from db import DataSource as database
    from db import RecordSet
    
    def main():
       print("hello")
    

    Run the main.py script as python3 -m main.main

    0 讨论(0)
提交回复
热议问题