0

I have this directory structure:

+--myproject
¦   +--code
¦   ¦    +--models
¦   ¦    ¦     __init__.py
¦   ¦    ¦     m.py
¦   ¦    ¦_
¦   ¦    
¦   ¦    +--resources
¦   ¦    ¦     __init_.py
¦   ¦    ¦     r.py
¦   ¦    ¦_
¦   ¦    
¦   ¦    app.py
¦   ¦    
¦   +--venv
¦   .gitignore
¦   requirements.txt
¦_

In m.py I have:

class M:
  pass

and in r.py I have:

from models.m import M  # HERE IS THE PROBLEM!

class R:
  pass
...

and in app.py:

from resources.r import R

Please note that when I want to create the pycharm project, I go to


File --> New Project --> choose myprojec directory as location -->

Create project existing sources --> Open the project in a New Window -->

pip install -r requirements.txt in pycharm terminal -->

cd code in my pycharm terminal --> run python app.py


My code is working correctly.

But Pycharm draws a red line under my import. It is giving me a false alarm. I know there should be some setting in Pychram to fix this? What is the fix for this?

Amin Ba
  • 1,603
  • 1
  • 13
  • 38
  • You have to set the correct interpreter for the project in the settings. – bad_coder Aug 13 '21 at 03:34
  • I set the `code` directory to source roots and it solved my problem. https://www.jetbrains.com/help/pycharm/configuring-project-structure.html – Amin Ba Aug 13 '21 at 14:26

0 Answers0