简体   繁体   中英

ImportError: No module named controller.api python?

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:

https://docs.python.org/3/tutorial/modules.html

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM