I have a django (but i think it's nor revelant here) project where I try to add a script i did before. So I put it in a subdirectory of my project, and i have this structure (I know it's a little bit of a mess at the moment but it won't stay exactly like that)
From views.py i want to import main.py (Especially the function excelToXml) . After searches on internet i found that code that i copied in views.py . If I undestood it right it add to the variable $PATH the directory parent of first_page and though, every subdirectory
CURRENT = os.path.dirname(os.path.abspath(__file__))
PARENT = os.path.dirname(CURRENT)
sys.path.append(PARENT)
from ExcelToXML.main import excelToXml
I also created a file __init.py__ in the directory ExcelToXML, this file is left empty.
However even I did all that i still get this error when i run the django server
File "c:\Users\CRA\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\django\bin\DevisVersOpen\DevisVersOpen\urls.py", line 18, in module
from first_page import views
File "c:\Users\CRA\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\django\bin\DevisVersOpen\first_page\views.py", line 13, in module
from ExcelToXML.main import excelToXml
ModuleNotFoundError: No module named 'ExcelToXML'
I didn't find any solution that I could understand on internet so I really don't know how to solve this
This is caused by the fact that the version of Python you're running your script with is not configured to search for modules where you've installed them. This happens when you use the wrong installation of pip to install packages.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With