What is the right way to create project structure in pycharm?

前端 未结 1 1463
离开以前
离开以前 2021-01-02 08:50

I\'m new to python and I don\'t know how to organize the project structure in the right way, so all auto imports would work in pycharm.

That\'s my current structure.

1条回答
  •  孤街浪徒
    2021-01-02 09:34

    import sys, os.path
    
    sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
    from Rabbit.RabbitReceiver import RabbitReceiver
    from Rabbit.RabbitSender import RabbitSender
    

    If you don't want to modify sys.path, the only way is to add -m flag when you run it

    python -m messaging_system.tests.PublisherSubscriberTest
    

    see How to fix "Attempted relative import in non-package" even with __init__.py

    edit

    OK, finally I found an ultimate answer: Relative imports for the billionth time

    I suggest you read that post carefully, from which I learned a lot.

    In short, if you want to do this, you have to add path-to-Rabbit to sys.path.

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