Search code examples
pythonimportmodulepython-importimporterror

My own modules can't be found -> Unresolved Reference


I have a Python project called restapi. The folder structure is the following:

restapi
|-data
|  |-[...]
|-docs
|  |-[...]
|-src
|  |-app.py
|  |-flaskWrapper.py
|  |-imageLoader.py
|  |-modelLoader.py
|  |-ocr.py
|-test
|  |-[...]

In app.py I import some stuff:

from imageLoader import Img
from modelLoader import Model
from PIL import Image
from flask import Flask, jsonify, request

But it doesn't work and the error message is Unresolved reference 'imageLoader' and the same with modelLoader. Does anyone have an idea what is wrong here?


Solution

  • That warning seems to be on PyCharm. You have to tell the base/root of your imports, which here is restapi/src/ so that PyCharm knows that your imports such as from imageLoader import Img are relative to the root path restapi/src/

    enter image description here

    On top of that, make sure that Python can find those imports when executed by setting the PYTHONPATH from the root restapi/src/

    export PYTHONPATH=${PYTHONPATH}:/path/to/restapi/src