What is the correct way to create a project structure in pycharm?

I am new to python and I do not know how to organize the project structure correctly, so all auto imports will work in pycharm.

This is my current structure.

enter image description here

This import is generated in PublisherSubscriberTest pycharm

from Rabbit.RabbitReceiver import RabbitReceiver
from Rabbit.RabbitSender import RabbitSender

But it does not work. This is the way out.

ImportError: no module named Rabbit.RabbitReceiver

What did I do wrong?

I am more familiar with java. And, for example, in java, I would just create a package with some classes, and then I could import them anywhere in my project. AFAIK is not the same with python.

Can anyone explain this to me?

EDIT1: Yes, I know about sys.path.append. I did it this way, but it seemed strange to me, and I want it to be possible to do without him.

+4
1
import sys, os.path

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

sys.path, - -m

python -m messaging_system.tests.PublisherSubscriberTest

. " non-package" __init__.py

, , :

, .

, , path-to-Rabbit sys.path.

+1

All Articles