Docker multiple containers broken imports

Relative imports don't work in my current project structure.

Project structure

project/
- services/
--- docker-compose-dev.yml
--- docker-compose-prod.yml
--- users/
----- __init__.py
----- Dockerfile-dev
----- Dockerfile-prod
----- project/
------- __init__.py
------- config.py
------- api/
--------- __init__.py
--------- models.py
--------- users.py
--- service_2/
----- __init__.py
----- Dockerfile-dev
----- Dockerfile-prod
----- project/
------- __init__.py
------- config.py
------- api/
--------- __init__.py
--------- models.py
--------- service_2.py

I have 10 services mapped out in this way.

In users.py my imports look like 

from project.api.models import Users

The project runs without a hitch when I run it from Terminal.

However, in Pycharm it does not recognize project.

 

I have tried setting each service as the sources root, but this sets a weird hierarchy where service_2 now thinks project is referring to the project folder in users.

I also tried setting a remote docker-compose interpreter without any luck in resolving this issue.

 

Thank you in advance.

Please sign in to leave a comment.