I am learning Django and not sure what is causing the error 'ModuleNotFoundError: No module named 'models''
even though the files are in the same folder
files are available here
File "/Users/mayanksharma/Library/Mobile Documents/com~apple~CloudDocs/for Stackoverflow/app-7-django/blogs/urls.py", line 1, in <module>
from . import views
File "/Users/mayanksharma/Library/Mobile Documents/com~apple~CloudDocs/for Stackoverflow/app-7-django/blogs/views.py", line 2, in <module>
from models import Post
ModuleNotFoundError: No module named 'models'
Do you mean by?
from .models import Post
Replace from . import views with:
import sys
sys.append('..')
import views
This was something to do with python reading path instead of from .models import Post or from . import views I gave from app.models import Post and that made it work
Related
After writing this -
VERIFICATION_SCRIPT = os.path.join(paths['APIMODEL_PATH'], 'research', 'object_detection', 'builders', 'model_builder_tf2_test.py')
!python {VERIFICATION_SCRIPT}
I am getting this error-
from keras.layers.preprocessing import image_preprocessing as image_ops
ModuleNotFoundError: No module named 'keras.layers.preprocessing'
This error is because there is no api named keras.layers.preprocessing. The correct name of this api is tensorflow.keras.preprocessing and you can import image from this api not image_preprocessing
Try using:
from tensorflow.keras.preprocessing import image as image_ops
in place of (incorrect way)
from keras.layers.preprocessing import image_preprocessing as image_ops
Please check this link for more details.
I have a project with two applications. They both use a mongo-engine database model file. Also they have to start in different Docker containers, but use the same Mongo database in the fird container. Now my app structure looks like this:
app_root/
app1/
database/
models.py
main.py
app2/
database/
models.py
main.py
And it works fine, BUT I have to support two same files database/models.py. I dont want to do this and I make the next structure:
app_root/
shared/
database/
models.py
app1/
main.py
app2/
main.py
Unfortunately it doesnt work for me, because when I try this in my main.py:
from ..shared.database.models import *
I get
Exception has occurred: ImportError
attempted relative import with no known parent package
And when I try
from app_root.shared.database.models import *
I get
Exception has occurred: ModuleNotFoundError No module named 'app_root'
Please, what do I do wrong?
In the file you perform the import, try adding this:
import os
import sys
sys.path.append(os.path.abspath('../../..'))
from app_root.shared.database.models import *
I have the following file structure
home/user/app.py
home/user/content/resource.py
home/user/content/call1.py
home/user/content/call2.py
I have imported resources.py in app.py as below:
import content.resource
Also, I have imported call1 and call2 in resource.py
import call1
import call2
The requirement is to run two tests individually.
run app.py
run resource.py
When I run app.py, it says cannot find call1 and call2.
When run resource.py, the file is running without any issues. How to run app.py python file to call import functions in resource.py and also call1.py and call2.py files?
All the 4 files having __init__ main function.
In your __init__ files, just create a list like this for each init, so for your user __init__: __all__ = ["app", "content"]
And for your content __init__: __all__ = ["resource", "call1", "call2"]
First try: export PYTHONPATH=/home/user<-- Make sure this is the correct absolute path.
If that doesn't solve the issue, try adding content to the path as well.
try: export PYTHONPATH=/home/user/:/home/user/content/
This should definitely work.
You will then import like so:
import user.app
import user.content.resource
NOTE
Whatever you want to use, you must import in every file. Don't bother importing in __init__. Just mention whatever modules that __init__ includes by doing __all__ = []
You have to import call1 and call2 in app.py if you want to call them there.
I'm doing some django stuffs using vs code and this error in the line 3 ("from") happend for no reason.
from django.urls import path
from * import views
urlpatterns = [path(" ",views,name="home")]
Your second import seems to be incorrect.
The syntax should be:
from <module> import <library / *>
In your case, it should be:
from views import *
That should be correct, as long as the views module do exist and can be found by python.
You cannot import like from *. Python expects a package name after from. If you are trying to import it from the relative path it might be something like
from . import views
Its a valid syntax error, and it did not happen for no-reason!
I am trying to write a script to get data from an internal website that exports to Excel, that data gets broken into smaller pieces and gets emailed to technicians. (metric data) I am trying to get into the website using robobrowser but I keep getting this:
C:\Users\user\AppData\Local\Programs\Python\Python36-32\Aging.py
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\Aging.py", line 3, in
from robobrowser import RoboBrowser
File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\site-packages\robobrowser-0.5.3-py3.6.egg\robobrowser__init__.py", line 3, in
from .browser import RoboBrowser
File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\site-packages\robobrowser-0.5.3-py3.6.egg\robobrowser\browser.py", line 7, in
from bs4 import BeautifulSoup
File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\site-packages\bs4__init__.py", line 30, in
from .builder import builder_registry, ParserRejectedMarkup
File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\site-packages\bs4\builder__init__.py", line 308, in
from . import _htmlparser
File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\site-packages\bs4\builder_htmlparser.py", line 7, in
from html.parser import (
ImportError: cannot import name 'HTMLParseError'
Here is the code:
import webbrowser
import re
from robobrowser import RoboBrowser
#Set BR module
br = RoboBrowser()
#open a website
br.open("https://www.whatever.com")
form = br.get_form()
form ['username'] = "username"
form ['password'] = "password"
br.submit_form(form)
Any help would be appreciated.
You should try reinstalling RoboBrowser and BeautifulSoup. What's happening is that when you import robobrowser, RoboBrowser then tries to import BeautifulSoup (a python module) which then tries to import _htmlparser (a python module that is part of the BeautifulSoup package), but it can't find that file and the load fails.
This is most likely caused by a missing or corrupted file (or maybe an out of date version). If you reinstall BeautifulSoup (and probably robobrowser to be safe) it should fix the problem.