Django ModuleNotFoundError when adding app - python

I'm using Visual Studio with Python tools to develop my Django project. I've create an app through the IDE. However after adding the app into the INSTALLED_APPS in my settings.py, it is always giving me ModuleNotFound Error
This is the directory structure.
This is how I've added the app
INSTALLED_APPS = [
# Add your apps here to enable them
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'kleis',
]
Stacktrace
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x00000228FCA30A60>
Traceback (most recent call last):
File "C:\Users\Sam\Documents\Exceptions\Projects\Kleis\Backend Django\Server\Server\env\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Users\Sam\Documents\Exceptions\Projects\Kleis\Backend Django\Server\Server\env\lib\site-packages\django\core\management\commands\runserver.py", line 113, in inner_run
autoreload.raise_last_exception()
File "C:\Users\Sam\Documents\Exceptions\Projects\Kleis\Backend Django\Server\Server\env\lib\site-packages\django\utils\autoreload.py", line 248, in raise_last_exception
raise _exception[1]
File "C:\Users\Sam\Documents\Exceptions\Projects\Kleis\Backend Django\Server\Server\env\lib\site-packages\django\core\management\__init__.py", line 327, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\Sam\Documents\Exceptions\Projects\Kleis\Backend Django\Server\Server\env\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Users\Sam\Documents\Exceptions\Projects\Kleis\Backend Django\Server\Server\env\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Sam\Documents\Exceptions\Projects\Kleis\Backend Django\Server\Server\env\lib\site-packages\django\apps\registry.py", line 89, in populate
app_config = AppConfig.create(entry)
File "C:\Users\Sam\Documents\Exceptions\Projects\Kleis\Backend Django\Server\Server\env\lib\site-packages\django\apps\config.py", line 90, in create
module = import_module(entry)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'kleis'

I tried with the above solutions but didnt get solved either.
If we miss to import the path in the newly created urls.py we will be seeing this error,
from django.urls import path (refer:https://docs.djangoproject.com/en/2.0/intro/tutorial01/#creating-a-project)
this will solve this error
Good Luck

Related

FCM-Django ModuleNotFoundError: No module named 'requests.adapters'

I'm trying to use fcm-django in my Django app to use Firebase messages and notifications.
But when I try to initialize the firebase app it gives me this error :
Traceback (most recent call last):
File "D:\Python\rolla_django\venv\lib\site-packages\django\core\management\base.py", line 415, in run_from_argv
connections.close_all()
File "D:\Python\rolla_django\venv\lib\site-packages\django\utils\connection.py", line 84, in close_all
for conn in self.all(initialized_only=True):
File "D:\Python\rolla_django\venv\lib\site-packages\django\utils\connection.py", line 76, in all
return [
File "D:\Python\rolla_django\venv\lib\site-packages\django\utils\connection.py", line 73, in __iter__
return iter(self.settings)
File "D:\Python\rolla_django\venv\lib\site-packages\django\utils\functional.py", line 57, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "D:\Python\rolla_django\venv\lib\site-packages\django\utils\connection.py", line 45, in settings
self._settings = self.configure_settings(self._settings)
File "D:\Python\rolla_django\venv\lib\site-packages\django\db\utils.py", line 148, in configure_settings
databases = super().configure_settings(databases)
File "D:\Python\rolla_django\venv\lib\site-packages\django\utils\connection.py", line 50, in configure_settings
settings = getattr(django_settings, self.settings_name)
File "D:\Python\rolla_django\venv\lib\site-packages\django\conf\__init__.py", line 92, in __getattr__
self._setup(name)
File "D:\Python\rolla_django\venv\lib\site-packages\django\conf\__init__.py", line 79, in _setup
self._wrapped = Settings(settings_module)
File "D:\Python\rolla_django\venv\lib\site-packages\django\conf\__init__.py", line 190, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "D:\Python\rolla_django\rolla_django\settings.py", line 14, in <module>
import firebase_admin
File "D:\Python\rolla_django\venv\lib\site-packages\firebase_admin\__init__.py", line 21, in <module>
from firebase_admin import credentials
File "D:\Python\rolla_django\venv\lib\site-packages\firebase_admin\credentials.py", line 21, in <module>
from google.auth.transport import requests
File "D:\Python\rolla_django\venv\lib\site-packages\google\auth\transport\requests.py", line 37, in <module>
import requests.adapters # pylint: disable=ungrouped-imports
ModuleNotFoundError: No module named 'requests.adapters'
Process finished with exit code 1
I've followed the Official documentation for fcm-django as follows :
requirements.txt
Django
djangorestframework
django-extensions
pymysql
firebase-admin
fcm-django
requests
Settings.py
from firebase_admin import credentials
import firebase_admin
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'fcm_django',
'django_extensions',
'accounts',
'projects',
'requests',
'static_data'
]
cred = credentials.Certificate(os.path.join(BASE_DIR, "rolla-9f502-firebase-adminsdk-wpo1z-31dba08f1e.json"))
firebase_admin.initialize_app(cred)
FCM_DJANGO_SETTINGS = {
"DELETE_INACTIVE_DEVICES": False,
"UPDATE_ON_DUPLICATE_REG_ID": True,
}
But still, I face the error when I try to run the project

Cloudinary & Django - Django3 does not support django.utils.six fix?

I am using Heroku to deploy an application that I made with Django 3.1.2 (python 3.6.12), and I am using Cloudinary to store uploaded images.
I am running into a ModuleNotFoundError (shown below) because cloudinary-storage imports django.utils.six, but Django 3.0 does not support django.utils.six.
I have researched a bit, but have not found a working answer. One suggestion was to downgrade to Django2 - but when I did this I started receiving many other errors for other parts of my application so I don't want to go this route if possible.
So now I am trying to figure out a way that I can use Django3 and Cloudinary together, and get around the problem that Django3 does not support django.utils.six. Any help/suggestions would be greatly appreciated
Here is the traceback:
Django Version: 3.1.2
Python Version: 3.6.12
Installed Applications:
['users.apps.UsersConfig',
'point_system.apps.PointSystemConfig',
'crispy_forms',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'cloudinary_storage',
'cloudinary']
Installed Middleware:
('whitenoise.middleware.WhiteNoiseMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py", line 179, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/django/views/generic/base.py", line 70, in view
return self.dispatch(request, *args, **kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/django/views/generic/base.py", line 98, in dispatch
return handler(request, *args, **kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/django/views/generic/list.py", line 157, in get
context = self.get_context_data()
File "/app/point_system/views.py", line 144, in get_context_data
temp.append(p.image.url)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/fields/files.py", line 62, in url
return self.storage.url(self.name)
File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/functional.py", line 240, in inner
self._setup()
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/files/storage.py", line 364, in _setup
self._wrapped = get_storage_class()()
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/files/storage.py", line 359, in get_storage_class
return import_string(import_path or settings.DEFAULT_FILE_STORAGE)
File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/module_loading.py", line 17, in import_string
module = import_module(module_path)
File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
<source code not available>
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
<source code not available>
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
<source code not available>
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
<source code not available>
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
<source code not available>
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
<source code not available>
File "/app/.heroku/python/lib/python3.6/site-packages/cloudinary_storage/storage.py", line 17, in <module>
from django.utils.six.moves.urllib.parse import urlsplit, urlunsplit, unquote
Exception Type: ModuleNotFoundError at /
Exception Value: No module named 'django.utils.six'
Some of the answers that I found that did not work:
ModuleNotFoundError: No module named 'django.utils.six'
ImportError: cannot import name 'six' from 'django.utils'
https://github.com/jazzband/django-sortedm2m/issues/151
Thanks in advance for your help, and please let me know if I need to provide any more information!

ModuleNotFoundError: No module named 'django_markdown2'

I'm currently doing Harvard Course about Web Programming. I need to convert my html page on website to markdown, so I installed into my conda virtual environment markdown2 and I added it to INSTALLED_APPS in settings.py. But I have a problem when I try to runserver or migrate I am getting an error ModuleNotFoundError. I tried to create another virtual environment but that doesn't work as well.
Thank you for your tips in advance.
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\petrk\anaconda3\envs\henv\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\petrk\anaconda3\envs\henv\lib\site-packages\django\core\management\__init__.py", line 377, in execute
django.setup()
File "C:\Users\petrk\anaconda3\envs\henv\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\petrk\anaconda3\envs\henv\lib\site-packages\django\apps\registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "C:\Users\petrk\anaconda3\envs\henv\lib\site-packages\django\apps\config.py", line 90, in create
module = import_module(entry)
File "C:\Users\petrk\anaconda3\envs\henv\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'django_markdown2'
INSTALLED_APPS = [
'encyclopedia',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_markdown2',
]
SOLVED
I had to install to my virtual enviroment pip install django-markdown2 instead of just markdown2.

Django Error Module 'Whitenoise' not found

I'm using whitenoise to deploy static files in prod, so according to whitenoise's docs, it's recommended to use it in development too.
So I followed the documentation and added the following to my settings.py file:
INSTALLED_APPS = [
'whitenoise.runserver_nostatic',
'django.contrib.admin',
...other
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
...other
]
But when I run the server using python manage.py runserver 0.0.0.0:8000, I get the error
ModuleNotFoundError: No module named 'whitenoise'
Full stack trace:
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/path/to/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "/path/to/venv/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/path/to/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 76, in raise_last_exception
raise _exception[1]
File "/path/to/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "/path/to/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "/path/to/venv/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/path/to/venv/lib/python3.7/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/path/to/venv/lib/python3.7/site-packages/django/apps/config.py", line 116, in create
mod = import_module(mod_path)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'whitenoise'
I checked using pip freeze and the module IS installed (v5.0.1) along with django 3.0.4. So why am I getting that error?
this issue will be resolved by installing whitenose module to your virtual environment or globally.
pip install whitenoise

JetBrains Pycharm - Getting error while debugging my project

I just switched to Mac from windows.
I imported my project in pycharm from GitHub but it is giving unknown errors.
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x10b75f6a8>
Traceback (most recent call last):
File "/Users/rajababu/anaconda/lib/python3.6/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Users/rajababu/anaconda/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 113, in inner_run
autoreload.raise_last_exception()
File "/Users/rajababu/anaconda/lib/python3.6/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
File "/Users/rajababu/anaconda/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/Users/rajababu/anaconda/lib/python3.6/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Users/rajababu/anaconda/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/rajababu/anaconda/lib/python3.6/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/Users/rajababu/anaconda/lib/python3.6/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/Users/rajababu/anaconda/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 948, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'import_export'
I think import_export is not in your INSTALLED_APPS.
Install import_export with pip
pip install django-import-export
and try again.
You need to install the import_export plugin. You can do this in PyCharm using File > Settings > Project Interpreter and press the "+" icon (search for it and install it). Make sure to add import_export to your INSTALLED_APPS variable in your settings as well.

Categories

Resources