1

I have specific project structure

- src
  - common/
    - constants/
      - __init__.py
    - database.py
  - user
    - create/
      - main.py
      - constants/
        - app_constants.py
        - __init__.py

I made common directory source root.

In main.py I have

from common import database
from constants import app_constants

Second import is showing Unresolved reference 'constants'

How to set PyCharm project structure to fix it?

psowa001
  • 725
  • 1
  • 6
  • 18
  • You are importing a module from a package, you're supposed to import classes/functions not the whole module. `app_constants` is a file, `app_constants.py` the import would work if there where an object in the `constants/__init__.py` called `app_constants`. So your import should be `from constants.app_constants import something`. – bad_coder Oct 14 '22 at 11:02
  • Besides that mistake set `src` as the ["sources root" in the IDE](https://stackoverflow.com/a/21241988/) – bad_coder Oct 14 '22 at 11:05

0 Answers0