0

I have this simple project structure. In the project's home directory, I have a module called 'service_api.py',which is a top level package. In the same home directory, I created a "demo.py", which calls the service_api:

from service_api import get_result;

'get_result' is a function defined in service_api.

This works fine. However, after I created a sub-directory 'service/' under home and moved 'demo.py' into 'service/', and run the same program, it complains:

ModuleNotFoundError: No module named 'service_api'

It's a top level module, and why it can't be imported? This occurs in a terminal, but if I execute it in PyCharm, it is still fine.

What's the issue?

marlon
  • 99
  • 1
  • 8
  • 1
    Possible duplicate of [How PyCharm imports differently than system command prompt (Windows)](https://stackoverflow.com/questions/54955891/how-pycharm-imports-differently-than-system-command-prompt-windows) – CristiFati Jul 14 '19 at 20:33
  • @CristiFati I am running Linux and from my virtual environment, it can access the python interpreter. Why does it still get the problem and how to fix it? – marlon Jul 14 '19 at 21:31

0 Answers0