Python

Unresolved reference python and project structure

I created a project. Project name is awesomeapplication. My packages are api, application. Then there is tmp package as well where I have the run.py file.

.
├── awesomeapplication
│   ├── api
│   │   ├── api.py
│   │   └── __init__.py
│   ├── config.py
│   ├── application
│   │   ├── __init__.py
│   │   └── manager.py
│   ├── requirements.txt
│   ├── tmp
│   │   ├── __init__.py
│   │   └── run.py
│   └── TODO.md
└── README.md

Now, in run.py file when I call,

from api import awesomeappapi, it should work. As ‘api’ is a package (with __init__.py ).

But there is a unresolved reference error. And I was scratching my head for sometimes. Then, I checked

https://www.jetbrains.com/help/pycharm/2016.3/accessing-project-structure.html

In File->Settings->project structure. And saw that my project root “awesomeapplication” was not included in source, rather the parent directory was.

Screenshot from 2017-05-07 12:24:17

So, myproject->awesomeapplication was folder structure and myproject was in sources, but not awesomeapplication.

So, I added awesomeapplication in sources. And problem was solved.

I learned that, when there are packages in a project, they will be discoverable in other packages only when the project root are added in ‘Sources’.

Very important to learn this basic thing right?

Thanks and Greetings.

Advertisements

One thought on “Unresolved reference python and project structure

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s