Cannot find reference 'module' in '__init__.py'

I've seen countless threads on the topic and have yet to find a solution. Adding anything to the PATH doesn't help, marking directories as "Source" and "Root" doesn't help, and so on.

The project structure is:

-app
--app
---models
---routes
---training

importing `from app.models ...` doesn't work, but adding the root `app` and doing `from app.app.models ...` works fine.

The problem is that it's wrong - `from app.app` compiles locally but not on the cluster where the service runs.

The initial `app` is the source and I'd like PyCharm to understand that.

We have several projects written the same exact way. In some of them, PyCharm does recognize the correct directory, and in this one it doesn't. I cannot find any differences between the projects in terms of configuration.

Please help.

0

Hi, 

Marking the top-level `app` directory "as source" should add it to PYTHONPATH and let PyCharm resolve import references from it's root. I tried imitating a project structure from your description and it works.

If it's not working for you, could you please provide a project sample?

0
I had this same problem in a project I'm working on and I solved it like this:

Create a new environment variable with the name :PYTHONPATH and the value: address of your project folder

After that, open cmd and type the command: echo %PYTHONPATH% -> It will return the path entered as a value if the variable is correct.

Close and reopen PyCharm and the problem will be fixed in a few seconds.

Hope it helps
0

请先登录再写评论。