Jimmy C
Jimmy C

Reputation: 9690

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

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?

Upvotes: 27

Views: 6281

Answers (2)

Spike Curtis
Spike Curtis

Reputation: 451

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.

Upvotes: 42

sorin
sorin

Reputation: 170846

That's because PyChar is a GUI application which means that it does not share any of your environment variables, which are usually defined in your home profile scripts.

Upvotes: -10

Related Questions