Why is PyCharm complaining on missing modules when using absolute imports?

pycharm, python

Solution

PyCharm needs to know which files in your tree are Python sources in order for it to figure out your module structure.

Open File -> Settings -> Project: -> Project Structure

Then mark `projects` as a source directory.

Problem

I have the following package structure: ``` projects/ package_name/ __init__.py model.py ``` In `__init__.py` I have the following import statement: ``` import package_name.model as model ``` PyCharm complains here that there is no module named `package_name`. But when I import the package from the terminal while standing in `projects/`, Python imports the package without problems. My working directory in PyCharm is as well `projects`, and I have added it to my `PYTHONPATH`. Why is PyCharm complaining despite it seems to work just fine, and how do I fix it?

Original source

Related problems