So I made my own project it worked with python manage.py runserver but when I tried with a new project, it's a challenge project and the challenge is to improve the django app. I use Python 3.8.1 (64-bit) and when I write python manage.py runserver on Admin Powershell it gives me this error:
Traceback (most recent call last):
File "C:\Users\thatp\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Users\thatp\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\thatp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\thatp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "C:\Users\thatp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\utils\autoreload.py", line 76, in raise_last_exception
raise _exception[1]
File "C:\Users\thatp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\thatp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\thatp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\thatp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "C:\Users\thatp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\apps\config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\thatp\AppData\Local\Programs\Python\Python38-32\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 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 "C:\djangoProjects\django-challenge-master\app\mailer\models.py", line 6, in <module>
from django.utils.encoding import python_2_unicode_compatible
ImportError: cannot import name 'python_2_unicode_compatible' from 'django.utils.encoding' (C:\Users\thatp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\utils\encoding.py)
So if someone could help me that would be awesome.
The error are in your model, see bellow:
from django.utils.encoding import python_2_unicode_compatible
ImportError: cannot import name 'python_2_unicode_compatible' from 'django.utils.encoding' (C:\Users\thatp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\utils\encoding.py
it only work on Django>=1.5, see here: https://stackoverflow.com/a/20741848/9710734
Related
I get the error below when I add 'graphene_django' inside INSTALLED_APPS in the settings.py.
After running
python3 manage.py runserver
graphene_django is installed successfully using
pip install django graphene_django
This is full error that I get:
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/usr/local/Cellar/python#3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 973, in _bootstrap_inner
self.run()
File "/usr/local/Cellar/python#3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 910, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.9/site-packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 115, in inner_run
autoreload.raise_last_exception()
File "/usr/local/lib/python3.9/site-packages/django/utils/autoreload.py", line 87, in raise_last_exception
raise _exception[1]
File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 381, in execute
autoreload.check_errors(django.setup)()
File "/usr/local/lib/python3.9/site-packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.9/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/usr/local/lib/python3.9/site-packages/django/apps/config.py", line 223, in create
import_module(entry)
File "/usr/local/Cellar/python#3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/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 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/usr/local/lib/python3.9/site-packages/graphene_django/__init__.py", line 1, in <module>
from .fields import DjangoConnectionField, DjangoListField
File "/usr/local/lib/python3.9/site-packages/graphene_django/fields.py", line 18, in <module>
from .utils import maybe_queryset
File "/usr/local/lib/python3.9/site-packages/graphene_django/utils/__init__.py", line 2, in <module>
from .utils import (
File "/usr/local/lib/python3.9/site-packages/graphene_django/utils/utils.py", line 6, in <module>
from django.utils.encoding import force_text
ImportError: cannot import name 'force_text' from 'django.utils.encoding' (/usr/local/lib/python3.9/site-packages/django/utils/encoding.py)
Any idea on what's going wrong here?
force_text is removed from Django 4.0
You can add this code to top of your settings.py :
import django
from django.utils.encoding import force_str
django.utils.encoding.force_text = force_str
Install graphene-django in this way. This resolves the issue for me.
pip install "graphene-django==3.0.0b7"
You can install graphene-django==3.0.0b7
It's beta version, but i don't know why graphene-django 2.15 does'nt work, when patch note said they fixed issue since 2.8.1 version.
Thank's to #Behoston from this Github issue for this solution
Use from django.utils.encoding imort force_str instead of force_text
I have tried looking for the solution in other threads but still stuck to the problem.
My python version is 3.9.5;
I reinstalled django to a lower version (it was 3.2.0, later installed 3.0)
INSTALLED_APPS = [
...
...
'django_filters',
]
error
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "c:\users\anika tabassum era\appdata\local\programs\python\python
line 954, in _bootstrap_inner
self.run()
File "c:\users\anika tabassum era\appdata\local\programs\python\python
line 892, in run
self._target(*self._args, **self._kwargs)
File "D:\DJPROJ\FINALS\DennisCRM\env\lib\site-packages\django\utils\au in wrapper
fn(*args, **kwargs)
File "D:\DJPROJ\FINALS\DennisCRM\env\lib\site-packages\django\core\manrver.py", line 110, in inner_run
autoreload.raise_last_exception()
File "D:\DJPROJ\FINALS\DennisCRM\env\lib\site-packages\django\utils\au in raise_last_exception
raise _exception[1]
File "D:\DJPROJ\FINALS\DennisCRM\env\lib\site-packages\django\core\man
line 375, in execute
autoreload.check_errors(django.setup)()
File "D:\DJPROJ\FINALS\DennisCRM\env\lib\site-packages\django\utils\au in wrapper
fn(*args, **kwargs)
File "D:\DJPROJ\FINALS\DennisCRM\env\lib\site-packages\django\__init__p
File "D:\DJPROJ\FINALS\DennisCRM\env\lib\site-packages\django\apps\reg populate
app_config = AppConfig.create(entry)
File "D:\DJPROJ\FINALS\DennisCRM\env\lib\site-packages\django\apps\con
create
import_module(entry)
File "c:\users\anika tabassum era\appdata\local\programs\python\python 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_unlo
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 855, in exec_modul
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_r
File "D:\DJPROJ\FINALS\DennisCRM\env\lib\site-packages\django_filters\
in <module>
File "D:\DJPROJ\FINALS\DennisCRM\env\lib\site-packages\django_filters\, in <module>
from django.utils import six
ImportError: cannot import name 'six' from 'django.utils' (D:\DJPROJ\FINsite-packages\django\utils\__init__.py)
installed as pip install django-filter.
In my filters.py I am getting the line import django_filters as yellow underlined and on hover shows Import "django_filters" could not be resolvedPylancereportMissingImports
Can anyone please guide me through? Thanks.
I create table in SQLite and generate code to models.py by cmd: python manage.py inspect > home/models.py, but I can't runserver and have this bug. Please help me!!!!!!!!!!!!!!!
PS E:\Code\Python\demoWeb> python manage.py runserver
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\threading.py", line 954, in _bootstrap_inner
self.run()
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\threading.py", line 892, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\commands\runserver.py", line 110, in inner_run
autoreload.raise_last_exception()
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\autoreload.py", line 87, in raise_last_exception
raise _exception[1]
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\__init__.py", line 375, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\apps\config.py", line 301, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\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 851, in exec_module
File "<frozen importlib._bootstrap_external>", line 988, in get_code
File "<frozen importlib._bootstrap_external>", line 918, in source_to_code
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
ValueError: source code string cannot contain null bytes
I'm getting DLL load failed when I try to run python manage.py runserver. It hapeens when I cd haddygirl and then run the previous command.
C:\Users\Lazxy\haddygirl>python manage.py runserver
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\Lazxy\Anaconda3\lib\threading.py", line 917, in _bootstrap_inner
self.run()
File "C:\Users\Lazxy\Anaconda3\lib\threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Lazxy\Anaconda3\lib\site-packages\django\utils\autoreload.py", line 54, in
wrapper
fn(*args, **kwargs)
File "C:\Users\Lazxy\Anaconda3\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Lazxy\Anaconda3\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "C:\Users\Lazxy\Anaconda3\lib\site-packages\django\apps\config.py", line 211, in
import_models
self.models_module = import_module(models_module_name)
File "C:\Users\Lazxy\Anaconda3\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\Lazxy\Anaconda3\lib\site-packages\django\contrib\auth\models.py", line 2, in
<module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "C:\Users\Lazxy\Anaconda3\lib\site-packages\django\contrib\auth\base_user.py", line 47, in
<module>
class AbstractBaseUser(models.Model):
File "C:\Users\Lazxy\Anaconda3\lib\site-packages\django\db\models\base.py", line 117, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "C:\Users\Lazxy\Anaconda3\lib\site-packages\django\db\models\base.py", line 321, in
add_to_class
value.contribute_to_class(cls, name)
File "C:\Users\Lazxy\Anaconda3\lib\site-packages\django\db\models\options.py", line 204, in
contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "C:\Users\Lazxy\Anaconda3\lib\site-packages\django\db\__init__.py", line 28, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Users\Lazxy\Anaconda3\lib\site-packages\django\db\utils.py", line 201, in __getitem__
backend = load_backend(db['ENGINE'])
File "C:\Users\Lazxy\Anaconda3\lib\site-packages\django\db\utils.py", line 110, in load_backend
return import_module('%s.base' % backend_name)
File "C:\Users\Lazxy\Anaconda3\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Users\Lazxy\Anaconda3\lib\site-packages\django\db\backends\sqlite3\base.py", line 13,
in <module>
from sqlite3 import dbapi2 as Database
File "C:\Users\Lazxy\Anaconda3\lib\sqlite3\__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "C:\Users\Lazxy\Anaconda3\lib\sqlite3\dbapi2.py", line 27, in <module>
from _sqlite3 import *
The error:
ImportError: DLL load failed: The specified module could not be found.
please help.
Seems that the driver for connect to sqlite are not found by the python installation.
Please share your python version. After Python 2.7.5 sqlite3 is shipped as a builtin dependencies.
Have a try with:
Use the builtin sqlite3
Install for python2
pip install pysqlite
Install for python3
pip install pysqlite3
I am currently undergoing a python course and learning how to use Django. I have just created mysite and am currently trying to test the Django server.
I ran the command below in the cmd and the output is as follows.
C:\Users\Win10\Desktop\Python\Newsite\mysite>python manage.py runserver
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x03A69780>
Traceback (most recent call last):
File "C:\Users\Win10\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django-1.11.2-py3.7.egg\django\utils\autoreload.py", line 227, in wrapper
fn(*args, **kwargs)
File "C:\Users\Win10\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django-1.11.2-py3.7.egg\django\core\management\commands\runserver.py", line 117, in inner_run
autoreload.raise_last_exception()
File "C:\Users\Win10\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django-1.11.2-py3.7.egg\django\utils\autoreload.py", line 250, in raise_last_exception
six.reraise(*_exception)
File "C:\Users\Win10\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django-1.11.2-py3.7.egg\django\utils\six.py", line 685, in reraise
raise value.with_traceback(tb)
File "C:\Users\Win10\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django-1.11.2-py3.7.egg\django\utils\autoreload.py", line 227, in wrapper
fn(*args, **kwargs)
File "C:\Users\Win10\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django-1.11.2-py3.7.egg\django\__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Win10\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django-1.11.2-py3.7.egg\django\apps\registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "C:\Users\Win10\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django-1.11.2-py3.7.egg\django\apps\config.py", line 94, in create
module = import_module(entry)
File "C:\Users\Win10\AppData\Local\Programs\Python\Python37-32\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\Win10\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django-1.11.2-py3.7.egg\django\contrib\admin\__init__.py", line 4, in <module>
from django.contrib.admin.filters import (
File "C:\Users\Win10\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django-1.11.2-py3.7.egg\django\contrib\admin\filters.py", line 10, in <module>
from django.contrib.admin.options import IncorrectLookupParameters
File "C:\Users\Win10\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django-1.11.2-py3.7.egg\django\contrib\admin\options.py", line 12, in <module>
from django.contrib.admin import helpers, widgets
File "C:\Users\Win10\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django-1.11.2-py3.7.egg\django\contrib\admin\widgets.py", line 151
'%s=%s' % (k, v) for k, v in params.items(),
^
SyntaxError: Generator expression must be parenthesized
Hope that i can be advised on this thank you! :(
Looks like you need to update your Django version. Look Here.
Try removing the existing version of django,
pip uninstall Django
and then reinstall using
pip install Django==1.11.17
Hopefully, that should fix the problem.