I am getting the error while trying to run a project in django.
The error is :
Watching for file changes with StatReloader Exception in thread
django-main-thread: Traceback (most recent call last):
I have installed it in the virtual environment.
The detailed error included below
(venv) D:\djEnv\t2>python3 manage.py runserver
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "c:\programdata\anaconda3\Lib\threading.py", line 926, in _bootstrap_inner
self.run()
File "c:\programdata\anaconda3\Lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "D:\djEnv\venv\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "D:\djEnv\venv\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "D:\djEnv\venv\lib\site-packages\django\utils\autoreload.py", line 76, in raise_last_exception
raise _exception[1]
File "D:\djEnv\venv\lib\site-packages\django\core\management\__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "D:\djEnv\venv\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "D:\djEnv\venv\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "D:\djEnv\venv\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "D:\djEnv\venv\lib\site-packages\django\apps\config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "D:\djEnv\venv\lib\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 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "D:\djEnv\venv\lib\site-packages\django\contrib\auth\models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "D:\djEnv\venv\lib\site-packages\django\contrib\auth\base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "D:\djEnv\venv\lib\site-packages\django\db\models\base.py", line 121, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "D:\djEnv\venv\lib\site-packages\django\db\models\base.py", line 325, in add_to_class
value.contribute_to_class(cls, name)
File "D:\djEnv\venv\lib\site-packages\django\db\models\options.py", line 208, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "D:\djEnv\venv\lib\site-packages\django\db\__init__.py", line 28, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "D:\djEnv\venv\lib\site-packages\django\db\utils.py", line 207, in __getitem__
backend = load_backend(db['ENGINE'])
File "D:\djEnv\venv\lib\site-packages\django\db\utils.py", line 111, in load_backend
return import_module('%s.base' % backend_name)
File "D:\djEnv\venv\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "D:\djEnv\venv\lib\site-packages\django\db\backends\sqlite3\base.py", line 14, in <module>
from sqlite3 import dbapi2 as Database
File "c:\programdata\anaconda3\Lib\sqlite3\__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "c:\programdata\anaconda3\Lib\sqlite3\dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: DLL load failed: The specified module could not be found.
The terminal keeps on buffering after this
Following the answer linked by #bmons, I updated my %PATH% to include
C:\ProgramData\Anaconda3\envs\py36\Lib\site-packages\pythonwin
C:\ProgramData\Anaconda3\envs\py36\Lib\sqlite3
Directions for updating the %PATH% variables on windows10: https://helpdeskgeek.com/windows-10/add-windows-path-environment-variable/
Related
Good morning, I have django 4.2 and djangorestframework 3.13.1, if I enable it in installed_aps I get the following error, I don't know if it's because of the django version or some dependency.
Anyone know what might be happening?
Thank you
Enabling it in settings.py is where the error occurs
Settings.py
DJANGO_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.gis',
'rest_framework',
]
The djangorestframework installs fine with the dependencies it needs, the installed versions appear in the pip list
pip list
asgiref 3.5.2
Django 4.2.dev20220721050550 /home/legacy/Documentos/proyectos/dtsc/django
django-debug-toolbar 3.5.0
djangorestframework 3.13.1
importlib-metadata 4.12.0
Pillow 9.2.0
pip 22.2.2
psycopg2-binary 2.9.3
pytz 2022.2.1
setuptools 60.9.3
sqlparse 0.4.2
wheel 0.37.1
zipp 3.8.1
Error
python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
Traceback (most recent call last):
File "/home/legacy/Documentos/proyectos/dtsc/django/django/template/utils.py", line 69, in __getitem__
return self._engines[alias]
KeyError: 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/legacy/Documentos/proyectos/dtsc/django/django/template/backends/django.py", line 129, in get_package_libraries
module = import_module(entry[1])
File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/home/legacy/Documentos/proyectos/dtsc/django/django/template/utils.py", line 69, in __getitem__
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
return self._engines[alias]
KeyError: 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/legacy/Documentos/proyectos/dtsc/django/django/template/backends/django.py", line 129, in get_package_libraries
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
module = import_module(entry[1])
File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/home/legacy/Documentos/proyectos/dtsc/lib/python3.9/site-packages/rest_framework/templatetags/rest_framework.py", line 12, in <module>
from rest_framework.renderers import HTMLFormRenderer
File "/home/legacy/Documentos/proyectos/dtsc/lib/python3.9/site-packages/rest_framework/renderers.py", line 17, in <module>
from django.http.multipartparser import parse_header
ImportError: cannot import name 'parse_header' from 'django.http.multipartparser' (/home/legacy/Documentos/proyectos/dtsc/django/django/http/multipartparser.py)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
self.run()
File "/usr/lib/python3.9/threading.py", line 892, in run
self._target(*self._args, **self._kwargs)
File "/home/legacy/Documentos/proyectos/dtsc/django/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/home/legacy/Documentos/proyectos/dtsc/django/django/core/management/commands/runserver.py", line 134, in inner_run
self.check(display_num_errors=True)
File "/home/legacy/Documentos/proyectos/dtsc/django/django/core/management/base.py", line 475, in check
all_issues = checks.run_checks(
File "/home/legacy/Documentos/proyectos/dtsc/django/django/core/checks/registry.py", line 89, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/home/legacy/Documentos/proyectos/dtsc/django/django/contrib/admin/checks.py", line 78, in check_dependencies
for engine in engines.all():
File "/home/legacy/Documentos/proyectos/dtsc/django/django/template/utils.py", line 94, in all
return [self[alias] for alias in self]
File "/home/legacy/Documentos/proyectos/dtsc/django/django/template/utils.py", line 94, in <listcomp>
return [self[alias] for alias in self]
File "/home/legacy/Documentos/proyectos/dtsc/django/django/template/utils.py", line 85, in __getitem__
engine = engine_cls(params)
File "/home/legacy/Documentos/proyectos/dtsc/django/django/template/backends/django.py", line 25, in __init__
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/home/legacy/Documentos/proyectos/dtsc/lib/python3.9/site-packages/rest_framework/templatetags/rest_framework.py", line 12, in <module>
from rest_framework.renderers import HTMLFormRenderer
File "/home/legacy/Documentos/proyectos/dtsc/lib/python3.9/site-packages/rest_framework/renderers.py", line 17, in <module>
from django.http.multipartparser import parse_header
ImportError: cannot import name 'parse_header' from 'django.http.multipartparser' (/home/legacy/Documentos/proyectos/dtsc/django/django/http/multipartparser.py)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/legacy/Documentos/proyectos/dtsc/observatorio/manage.py", line 22, in <module>
main()
File "/home/legacy/Documentos/proyectos/dtsc/observatorio/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/legacy/Documentos/proyectos/dtsc/django/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/home/legacy/Documentos/proyectos/dtsc/django/django/core/management/__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/legacy/Documentos/proyectos/dtsc/django/django/core/management/base.py", line 402, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/legacy/Documentos/proyectos/dtsc/django/django/core/management/commands/runserver.py", line 74, in execute
options["libraries"] = self.get_templatetag_libraries(libraries)
File "/home/legacy/Documentos/proyectos/dtsc/django/django/template/backends/django.py", line 43, in get_templatetag_libraries
super().execute(*args, **options)
libraries = get_installed_libraries()
File "/home/legacy/Documentos/proyectos/dtsc/django/django/core/management/base.py", line 448, in execute
File "/home/legacy/Documentos/proyectos/dtsc/django/django/template/backends/django.py", line 117, in get_installed_libraries
output = self.handle(*args, **options)
File "/home/legacy/Documentos/proyectos/dtsc/django/django/core/management/commands/runserver.py", line 111, in handle
return {
File "/home/legacy/Documentos/proyectos/dtsc/django/django/template/backends/django.py", line 117, in <dictcomp>
self.run(**options)
File "/home/legacy/Documentos/proyectos/dtsc/django/django/core/management/commands/runserver.py", line 118, in run
return {
File "/home/legacy/Documentos/proyectos/dtsc/django/django/template/backends/django.py", line 106, in get_template_tag_modules
autoreload.run_with_reloader(self.inner_run, **options)
File "/home/legacy/Documentos/proyectos/dtsc/django/django/utils/autoreload.py", line 680, in run_with_reloader
for name in get_package_libraries(pkg):
File "/home/legacy/Documentos/proyectos/dtsc/django/django/template/backends/django.py", line 131, in get_package_libraries
raise InvalidTemplateLibrary(
django.template.library.InvalidTemplateLibrary: Invalid template library specified. ImportError raised when trying to load 'rest_framework.templatetags.rest_framework': cannot import name 'parse_header' from 'django.http.multipartparser' (/home/legacy/Documentos/proyectos/dtsc/django/django/http/multipartparser.py)
start_django(reloader, main_func, *args, **kwargs)
File "/home/legacy/Documentos/proyectos/dtsc/django/django/utils/autoreload.py", line 661, in start_django
reloader.run(django_main_thread)
File "/home/legacy/Documentos/proyectos/dtsc/django/django/utils/autoreload.py", line 343, in run
autoreload_started.send(sender=self)
File "/home/legacy/Documentos/proyectos/dtsc/django/django/dispatch/dispatcher.py", line 176, in send
return [
File "/home/legacy/Documentos/proyectos/dtsc/django/django/dispatch/dispatcher.py", line 177, in <listcomp>
(receiver, receiver(signal=self, sender=sender, **named))
File "/home/legacy/Documentos/proyectos/dtsc/django/django/template/autoreload.py", line 43, in watch_for_template_changes
for directory in get_template_directories():
File "/home/legacy/Documentos/proyectos/dtsc/django/django/template/autoreload.py", line 16, in get_template_directories
for backend in engines.all():
File "/home/legacy/Documentos/proyectos/dtsc/django/django/template/utils.py", line 94, in all
return [self[alias] for alias in self]
File "/home/legacy/Documentos/proyectos/dtsc/django/django/template/utils.py", line 94, in <listcomp>
return [self[alias] for alias in self]
File "/home/legacy/Documentos/proyectos/dtsc/django/django/template/utils.py", line 85, in __getitem__
engine = engine_cls(params)
File "/home/legacy/Documentos/proyectos/dtsc/django/django/template/backends/django.py", line 25, in __init__
options["libraries"] = self.get_templatetag_libraries(libraries)
File "/home/legacy/Documentos/proyectos/dtsc/django/django/template/backends/django.py", line 43, in get_templatetag_libraries
libraries = get_installed_libraries()
File "/home/legacy/Documentos/proyectos/dtsc/django/django/template/backends/django.py", line 117, in get_installed_libraries
return {
File "/home/legacy/Documentos/proyectos/dtsc/django/django/template/backends/django.py", line 117, in <dictcomp>
return {
File "/home/legacy/Documentos/proyectos/dtsc/django/django/template/backends/django.py", line 106, in get_template_tag_modules
for name in get_package_libraries(pkg):
File "/home/legacy/Documentos/proyectos/dtsc/django/django/template/backends/django.py", line 131, in get_package_libraries
raise InvalidTemplateLibrary(
django.template.library.InvalidTemplateLibrary: Invalid template library specified. ImportError raised when trying to load 'rest_framework.templatetags.rest_framework': cannot import name 'parse_header' from 'django.http.multipartparser' (/home/legacy/Documentos/proyectos/dtsc/django/django/http/multipartparser.py)
When I run python manage.py runserver, my django server runs and I can see my webpage, however some of the tailwind doesn't work.
When I then stop that server and run python manage.py tailwind start, the localhost:8000 doesn't show my webpage, but my terminal says that it is running.
When I then stop the tailwind server running, and run python manage.py runserver, I get an error saying NameError: name '_mysql' is not defined.
I am unsure why this is happening, here is my full stack trace:
Traceback (most recent call last):
File "/Users/maxculley/Desktop/ESD COURSEWORK/venv/lib/python3.8/site-packages/MySQLdb/__init__.py", line 18, in <module>
from . import _mysql
ImportError: dlopen(/Users/maxculley/Desktop/ESD COURSEWORK/venv/lib/python3.8/site-packages/MySQLdb/_mysql.cpython-38-darwin.so, 2): Library not loaded: #rpath/libmysqlclient.21.dylib
Referenced from: /Users/maxculley/Desktop/ESD COURSEWORK/venv/lib/python3.8/site-packages/MySQLdb/_mysql.cpython-38-darwin.so
Reason: image not found
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/Users/maxculley/Desktop/ESD COURSEWORK/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 425, in execute_from_command_line
utility.execute()
File "/Users/maxculley/Desktop/ESD COURSEWORK/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute
django.setup()
File "/Users/maxculley/Desktop/ESD COURSEWORK/venv/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/maxculley/Desktop/ESD COURSEWORK/venv/lib/python3.8/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/Users/maxculley/Desktop/ESD COURSEWORK/venv/lib/python3.8/site-packages/django/apps/config.py", line 300, in import_models
self.models_module = import_module(models_module_name)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/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 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Users/maxculley/Desktop/ESD COURSEWORK/venv/lib/python3.8/site-packages/django/contrib/auth/models.py", line 3, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/Users/maxculley/Desktop/ESD COURSEWORK/venv/lib/python3.8/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "/Users/maxculley/Desktop/ESD COURSEWORK/venv/lib/python3.8/site-packages/django/db/models/base.py", line 122, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/Users/maxculley/Desktop/ESD COURSEWORK/venv/lib/python3.8/site-packages/django/db/models/base.py", line 326, in add_to_class
value.contribute_to_class(cls, name)
File "/Users/maxculley/Desktop/ESD COURSEWORK/venv/lib/python3.8/site-packages/django/db/models/options.py", line 207, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/Users/maxculley/Desktop/ESD COURSEWORK/venv/lib/python3.8/site-packages/django/utils/connection.py", line 15, in __getattr__
return getattr(self._connections[self._alias], item)
File "/Users/maxculley/Desktop/ESD COURSEWORK/venv/lib/python3.8/site-packages/django/utils/connection.py", line 62, in __getitem__
conn = self.create_connection(alias)
File "/Users/maxculley/Desktop/ESD COURSEWORK/venv/lib/python3.8/site-packages/django/db/utils.py", line 204, in create_connection
backend = load_backend(db['ENGINE'])
File "/Users/maxculley/Desktop/ESD COURSEWORK/venv/lib/python3.8/site-packages/django/db/utils.py", line 111, in load_backend
return import_module('%s.base' % backend_name)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/Users/maxculley/Desktop/ESD COURSEWORK/venv/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 15, in <module>
import MySQLdb as Database
File "/Users/maxculley/Desktop/ESD COURSEWORK/venv/lib/python3.8/site-packages/MySQLdb/__init__.py", line 24, in <module>
version_info, _mysql.version_info, _mysql.__file__
NameError: name '_mysql' is not defined
I also encountered the same error last few days, just found this solution and it works for me, hope it helps!
Use the following command to check mysqlclient is installed or not: pip freeze
Add env variable to ~/.zshrc for zsh, or ~/.bashrc or
~/.bash_profile for bash etc.):
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
Apply change by running
source ~/.your_shell_config_file
Source: https://medium.com/#cui.shinan0812/django-reason-image-not-found-nameerror-name-mysql-is-not-defined-a0d834c2d7b4
I am trying to connect Django and MySQL, but I am getting the error below
Error
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/Users/amitgupta/env1/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 16, in <module>
import MySQLdb as Database
ModuleNotFoundError: No module named 'MySQLdb'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/Cellar/python/3.7.7/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.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/Users/amitgupta/env1/lib/python3.7/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "/Users/amitgupta/env1/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/Users/amitgupta/env1/lib/python3.7/site-packages/django/utils/autoreload.py", line 76, in raise_last_exception
raise _exception[1]
File "/Users/amitgupta/env1/lib/python3.7/site-packages/django/core/management/__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "/Users/amitgupta/env1/lib/python3.7/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "/Users/amitgupta/env1/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/amitgupta/env1/lib/python3.7/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/Users/amitgupta/env1/lib/python3.7/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/usr/local/Cellar/python/3.7.7/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 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Users/amitgupta/env1/lib/python3.7/site-packages/django/contrib/auth/models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/Users/amitgupta/env1/lib/python3.7/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "/Users/amitgupta/env1/lib/python3.7/site-packages/django/db/models/base.py", line 121, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/Users/amitgupta/env1/lib/python3.7/site-packages/django/db/models/base.py", line 325, in add_to_class
value.contribute_to_class(cls, name)
File "/Users/amitgupta/env1/lib/python3.7/site-packages/django/db/models/options.py", line 208, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/Users/amitgupta/env1/lib/python3.7/site-packages/django/db/__init__.py", line 28, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/Users/amitgupta/env1/lib/python3.7/site-packages/django/db/utils.py", line 207, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Users/amitgupta/env1/lib/python3.7/site-packages/django/db/utils.py", line 111, in load_backend
return import_module('%s.base' % backend_name)
File "/usr/local/Cellar/python/3.7.7/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 "/Users/amitgupta/env1/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 21, in <module>
) from err
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?
Here, is part of my settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'first_django_project',
'USER':'root',
'PASSWORD':'root',
'HOST':'localhost'
}
}
And I used the following command for connector
pip install mysql-connector
I am trying this:
https://pypi.org/project/mysql-connector/
I am yet to try this approach:
https://dev.mysql.com/doc/connector-python/en/connector-python-django-backend.html
So, what is the mistake I am doing here, or is the whole approach wrong? Please, help me.
Thanks
I was trying to run a python program on my computer, the command I use is
py -3 manage.py runserver,
but I ran into an error and I couldn't find any helpful posts online that can solve this problem.
Python version is Python 3.7.3
Django version is 2.2
Here is the error message:
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\threading.py", line 917, in _bootstrap_inner
self.run()
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\autoreload.py", line 77, in raise_last_exception
raise _exception[0](_exception[1]).with_traceback(_exception[2])
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\django\apps\config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\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 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\Desktop\Intern\Diversity_Policy_Site\blog\models.py", line 4, in <module>
from .search import PolicyIndex
File "C:\Users\Desktop\Intern\Diversity_Policy_Site\blog\search.py", line 14, in <module>
connections.create_connection(hosts=["https://dd90577b842c4f9396ca1846612e98df.us-east-1.aws.found.io:9243"], http_auth=('elastic', 'Mq2jdfPLSRG1m8qxp4vd0qNa'))
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\elasticsearch_dsl\connections.py", line 66, in create_connection
conn = self._conns[alias] = Elasticsearch(**kwargs)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\elasticsearch\client\__init__.py", line 206, in __init__
self.transport = transport_class(_normalize_hosts(hosts), **kwargs)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\elasticsearch\transport.py", line 108, in __init__
self.set_connections(hosts)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\elasticsearch\transport.py", line 157, in set_connections
connections = list(zip(connections, hosts))
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\elasticsearch\transport.py", line 154, in _create_connection
return self.connection_class(**kwargs)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\elasticsearch\connection\http_urllib3.py", line 161, in __init__
"Root certificates are missing for certificate "
elasticsearch.exceptions.ImproperlyConfigured: Root certificates are missing for certificate validation. Either pass them in using the ca_certs parameter or install certifi to use it automatically.
Traceback (most recent call last):
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\django\apps\registry.py", line 155, in get_app_config
return self.app_configs[app_label]
KeyError: 'admin'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\commands\runserver.py", line 60, in execute
super().execute(*args, **options)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\commands\runserver.py", line 95, in handle
self.run(**options)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\commands\runserver.py", line 102, in run
autoreload.run_with_reloader(self.inner_run, **options)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\autoreload.py", line 579, in run_with_reloader
start_django(reloader, main_func, *args, **kwargs)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\autoreload.py", line 564, in start_django
reloader.run(django_main_thread)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\autoreload.py", line 272, in run
get_resolver().urlconf_module
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\django\urls\resolvers.py", line 564, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\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 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\Desktop\Intern\Diversity_Policy_Site\mysite\urls.py", line 22, in <module>
path('admin/', admin.site.urls),
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\functional.py", line 256, in inner
self._setup()
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\django\contrib\admin\sites.py", line 529, in _setup
AdminSiteClass = import_string(apps.get_app_config('admin').default_site)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\django\apps\registry.py", line 162, in get_app_config
raise LookupError(message)
LookupError: No installed app with label 'admin'.
The above code is the error I have, the posts I found online were not helpful.
type this command in cmd:
pip install certifi
and the above error should be solved.
I have created a django project for which i used MySQL database. I have mysql-python connector in mysql installed tools. I am not sure whether i set a required path in environmental variables. When i running the server, it raising an error :
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'. I would appreciate helping me solve this.
Traceback:
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x0000000004F167B8>
Traceback (most recent call last):
File "c:\python34\lib\site-packages\django\db\backends\mysql\base.py", line 25, in <module>
import MySQLdb as Database
ImportError: No module named 'MySQLdb'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\python34\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "c:\python34\lib\site-packages\django\core\management\commands\runserver.py", line 113, in inner_run
autoreload.raise_last_exception()
File "c:\python34\lib\site-packages\django\utils\autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
File "c:\python34\lib\site-packages\django\utils\six.py", line 685, in reraise
raise value.with_traceback(tb)
File "c:\python34\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "c:\python34\lib\site-packages\django\__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "c:\python34\lib\site-packages\django\apps\registry.py", line 108, in populate
app_config.import_models(all_models)
File "c:\python34\lib\site-packages\django\apps\config.py", line 199, in import_models
self.models_module = import_module(models_module_name)
File "c:\python34\lib\importlib\__init__.py", line 104, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2231, in _gcd_import
File "<frozen importlib._bootstrap>", line 2214, in _find_and_load
File "<frozen importlib._bootstrap>", line 2203, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1448, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "c:\python34\lib\site-packages\django\contrib\auth\models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "c:\python34\lib\site-packages\django\contrib\auth\base_user.py", line 52, in <module>
class AbstractBaseUser(models.Model):
File "c:\python34\lib\site-packages\django\db\models\base.py", line 119, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "c:\python34\lib\site-packages\django\db\models\base.py", line 316, in add_to_class
value.contribute_to_class(cls, name)
File "c:\python34\lib\site-packages\django\db\models\options.py", line 214, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "c:\python34\lib\site-packages\django\db\__init__.py", line 33, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "c:\python34\lib\site-packages\django\db\utils.py", line 211, in __getitem__
backend = load_backend(db['ENGINE'])
File "c:\python34\lib\site-packages\django\db\utils.py", line 115, in load_backend
return import_module('%s.base' % backend_name)
File "c:\python34\lib\importlib\__init__.py", line 104, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "c:\python34\lib\site-packages\django\db\backends\mysql\base.py", line 28, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'
You need to install:
pip install mysqlclient
Run pip install mysql-python before making any migrations.