简体   繁体   中英

ModuleNotFound Error when trying to import variable from script

I have a python script named "WhatsApp_to_Excel.py". There is a variable there that I need to use for a Django project I'm making. So I'm trying to import the module to the models.py file. This is my folder hierarchy-

在此处输入图像描述

Then I make my import like this-

在此处输入图像描述

But even though pycharm auto-completed the module's name, when I run the server I get the no module found error.

在此处输入图像描述

I'm running my code from a virtual environment, but I don't see how this can be the problem. I've tried to import the module in an absolute way, but it didn't work and it's rather weird that pycharm DOES recognize the module.

Does anybody Have any ideas on how to solve the problem? Would appreciate any help:-)

Try to put that WhatsApp_to_Excel.py file in the same directory of models.py

Thank you guys! I solved the problem using your advice-

  1. I moved my python script inside the folder with models.py (an init file was created automatically).

  2. I've imported a variable from my script using this code

    from.WhatsApp_to_Excel import TXT_PATH

And it works!!

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