Hi all,
I want to use Django models in my Streamlit app, but when I import the model, error says “No module named data_labelling.models”
The following is my file system
data_labelling
– models.py
data_validation
– UIDesign.py
both data_labelling and data_validation are apps that under a Django project.
In “UIDesign.py”, I write from data_labelling.models import ImageLabel.
When I run streamlit run UIDesign, I get an error message says ImportError: No module named data_labelling.models
I wonder why I see this error? and How to fix that?
At a glance it looks like this is unrelated to Streamlit. It’s more of a Python import system issue.
To check whether my hypothesis is right, try running UIDesign.py without Streamlit by just calling:
python UIDesign.py
…and see if you get the same ImportError in the terminal. My guess is the error will still be there.
Here’s what I think is happening: since UIDesign.py and models.py are in sibling folders, one can’t access the other unless you tell the import system to go up a level first, like this:
from ..data_labelling.models import ImageLabel
Note the .. in the import line. That’s a new Python3 feature that lets you navigate up your folder structure to find imports. (And in Python2 there’s no way to do that, so if you’re still using 2.x, you should refactor your folder structure)
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.