1

I have the following directory structure for my Python project:

lib 
    __init__.py
    tasks.py
    api(directory)
        __init__.py
        app.py

Now, I want to import the tasks module into app.py. If I just type

import tasks

it magically works in Pycharm, but when executed via bash I get an error message saying "No module named tasks". I also tried

from .. import tasks

which gives me

ValueError: attempted relative import beyond top-level package

What am I doing wrong? Why does import tasks work when executed in Pycharm?

Gasp0de
  • 1,199
  • 2
  • 12
  • 30
  • How did you "execut[e] via bash"? Does [this answer](https://stackoverflow.com/a/14132912) help? – Cong Ma Feb 26 '18 at 11:32
  • This helped me to understand some of my problems, thank you. I am still really confused why it works when executed with pycharm, and I still can't get behind the whole package thing. I would have thought I could execute it as a module using `python -m lib.api.app` from the lib directory, but that just gives me "No module named lib" – Gasp0de Feb 26 '18 at 12:51

0 Answers0