python – Importing module not working

python – Importing module not working

Your directory structure let me think that you should try to import like this :

from first_page.ExcelToXML.main import excelToXml

because the ExcelToXML is under the first_page module, so it is viewed as a submodule of first_page.

Check this for details on what is init.py file What is __init__.py for?

The init.py file should be present in every directory and sub directories whose classes should be made visible for import. In your case, the I am suspecting that the parent directory does not have the init.py file. Add the file in the parent directory and import it as follows

import first_page.ExcelToXML

python – Importing module not working

Okay hello, the solution you found is (I think) a mess, you should read the official documentation about it https://docs.python.org/3.6/tutorial/modules.html#packages.
In short just add from .idea.main import excelToXml.
If it does not work, rename .idea folder to idea(without the dot) and add in your views.py this line :from idea.main import excelToXml

Leave a Reply

Your email address will not be published. Required fields are marked *