6

I'm annoyed about the import logic when I write Python3 code in PyCharm Community Edition, Below is my structure.

project
├── orm.py
├── app.py
├── coroweb.py

in app.py, I import orm use below codes.

from . import orm
from .coroweb import xxx

It looks good in PyCharm, but when I run app.py, it will failed due to below error

ImportError: cannot import name 'orm'

Then, I use related import like this.

import orm
from coroweb import xxx

it running good but has import error in PyCharm. It's Unresolved reference. I want to use code tracing in PyCharm, so I want to know how to fix this issue.

Sraw
  • 18,892
  • 11
  • 54
  • 87
red_herring
  • 157
  • 2
  • 7

1 Answers1

4

You may try 2 things:

  • add __init__.py file in your project directory
  • right click on project and add project to Sources Root p
Tomasz
  • 1,895
  • 1
  • 14
  • 17