ImportError: No module named controller.api python?
Question:
In file sched.py
I import controller.api
:
# -*- coding: utf-8 -*-
import controller.api
But python raises an error:
python sched.py
Traceback (most recent call last):
File "sched.py", line 2, in <module>
import controller.api
File sched.py
is placed in the controller
folder.
Inside controller
I have file api.py
Why does Python gives me this error?
Answers:
You need to place an empty file named __init__.py in your ‘controller’ directory. This file denotes that directory as being a Python module. See:
In my case (using PyCharm) I renamed the file and for some reason was throwing the ‘No Module Name’ error although I renamed it with the same name specified in my openapi file. Deleting and creating the file again with the correct name fixed the error
In file sched.py
I import controller.api
:
# -*- coding: utf-8 -*-
import controller.api
But python raises an error:
python sched.py
Traceback (most recent call last):
File "sched.py", line 2, in <module>
import controller.api
File sched.py
is placed in the controller
folder.
Inside controller
I have file api.py
Why does Python gives me this error?
You need to place an empty file named __init__.py in your ‘controller’ directory. This file denotes that directory as being a Python module. See:
In my case (using PyCharm) I renamed the file and for some reason was throwing the ‘No Module Name’ error although I renamed it with the same name specified in my openapi file. Deleting and creating the file again with the correct name fixed the error