1

I am using eclipse with pyDev plugin and my python application in flask has the following structure:

[app]
├── __init__.py
├── main
│    ├── __init__.py
│    ├── controller.py
│    └── actions.py
├── classes
│   ├── __init__.py
│   └── helpme.py

as seen in this structure, app/, main/ and classes/ are packages and they have modules inside of them.

In controller.py module in main/ package, i am trying to import a class in helpme.py in classes/ package like this:

from ..util.helpme import helper_class

Here helper_class is a class in helpme.py with helper methods. When I do a python run of this application in eclipse, i always get the following error:

from ..util.helpme import helper_class

ValueError: Attempted relative import in non-package

I read a lot of questions/answers in stackoverflow option but none of them seem to fit in the bill here. Not sure how to resolve this issue.

Hary
  • 1,127
  • 4
  • 24
  • 51
  • Is this Python 2 or 3? – stanleyli Apr 21 '17 at 19:37
  • Do these answer your question: http://stackoverflow.com/questions/11536764/how-to-fix-attempted-relative-import-in-non-package-even-with-init-py and http://stackoverflow.com/questions/14132789/relative-imports-for-the-billionth-time ? – BrenBarn Apr 21 '17 at 19:38
  • It's python 2.7. In the post that you shared, it uses python -m pkg.tests.core_test. I am not sure where do I specify this option while using eclipse to run my code. – Hary Apr 21 '17 at 21:38
  • `helpme.py` is in `classes` directory, then shouldn't the import be `from ..classes.helpme import helper_class` ? – chickity china chinese chicken Apr 22 '17 at 03:40

0 Answers0