N
N
noob2222021-02-01 22:20:53
Python
noob222, 2021-02-01 22:20:53

How to make modules import normally?

Good day, I have several files and I import functions into one. shown as below.

Example #1
import settings

Example #2
from app import settings

If you run it as in example No. 1, it works both in PyCharm and in docker-compse, but in PyCharm it emphasizes (there is no such module).
If I change it to example No. 2, I get an error in docker-compose, underlining is removed in PyCharm
Error in docker-compose
ModuleNotFoundError: No module named 'app'


The problem is that the functions increase and it is not convenient to quickly switch to the desired one if it is imported from another file. But to work both in docker-compose and in PyCharm. Do not tell me how to solve?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
_
_, 2021-02-01
@mrxor

You have different PYTHONPATHs locally and in the docker, conditionally /path_to_project/app is added in one, not in the other.
Alternatively, add the desired paths to the PYTHONPATH in docker.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question