I am fairly new to Django and I have installed and am trying to use crispy forms in my web app.I have added crispy_forms to my installed apps with a comma after it. When I run the server I get this error:
Watching for file changes with StatReloader
Performing system checks...
Exception in thread Thread-3:
Traceback (most recent call last):
File "c:\users\amart\django\django\template\utils.py", line 66, in __getitem__
return self._engines[alias]
KeyError: 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\users\amart\django\django\template\backends\django.py", line 121, in get_package_libraries
module = import_module(entry[1])
File "C:\Users\amart\AppData\Local\Programs\Python\Python36-32\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 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\amart\AppData\Local\Programs\Python\Python36-32\lib\site-packages\crispy_forms\templatetags\crispy_forms_field.py", line 10, in <module>
from crispy_forms.utils import TEMPLATE_PACK, get_template_pack
File "C:\Users\amart\AppData\Local\Programs\Python\Python36-32\lib\site-packages\crispy_forms\utils.py", line 11, in <module>
from django.utils.lru_cache import lru_cache
ModuleNotFoundError: No module named 'django.utils.lru_cache'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\amart\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Users\amart\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "c:\users\amart\django\django\utils\autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "c:\users\amart\django\django\core\management\commands\runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "c:\users\amart\django\django\core\management\base.py", line 390, in check
include_deployment_checks=include_deployment_checks,
File "c:\users\amart\django\django\core\management\base.py", line 377, in _run_checks
return checks.run_checks(**kwargs)
File "c:\users\amart\django\django\core\checks\registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "c:\users\amart\django\django\contrib\admin\checks.py", line 59, in check_dependencies
for engine in engines.all():
File "c:\users\amart\django\django\template\utils.py", line 90, in all
return [self[alias] for alias in self]
File "c:\users\amart\django\django\template\utils.py", line 90, in <listcomp>
return [self[alias] for alias in self]
File "c:\users\amart\django\django\template\utils.py", line 81, in __getitem__
engine = engine_cls(params)
File "c:\users\amart\django\django\template\backends\django.py", line 25, in __init__
options['libraries'] = self.get_templatetag_libraries(libraries)
File "c:\users\amart\django\django\template\backends\django.py", line 43, in get_templatetag_libraries
libraries = get_installed_libraries()
File "c:\users\amart\django\django\template\backends\django.py", line 108, in get_installed_libraries
for name in get_package_libraries(pkg):
File "c:\users\amart\django\django\template\backends\django.py", line 125, in get_package_libraries
"trying to load '%s': %s" % (entry[1], e)
django.template.library.InvalidTemplateLibrary: Invalid template library specified. ImportError raised when trying to load 'crispy_forms.templatetags.crispy_forms_field': No module named 'django.utils.lru_cache'
I don't know what is wrong with my code. I have found some other users who have issues using crispy forms but are getting a different error. They were also unable to import crispy forms from the python shell but that is working for me. Even if I only add crispy forms to my installed apps without trying to apply it in my templates, I still get an error. Please let me know what I'm doing wrong. Thanks in advance.
Your version of django-crispy-forms is outdated, this has been fixed.
Update it by running:
pip install django-crispy-forms -U
-U makes pip upgrade your current installation to the newest.
You can find more about it by running pip install -h
The problem has been solved. I uninstalled the django version I had and used:
pip install Django==2.1.7
Thank you #YugandharChaudhari for helping me realize to change versions.
Related
I'm having a WSGI error while following the installation set up for django-cms from th official documentation.
I ran test with python manage.py cms check and it was sucessful.
Checking django CMS installation
Sekizai
Sekizai is installed [OK]
Sekizai template context processor is installed [OK]
Sekizai namespaces 'js' and 'css' found in 'home.html' [OK]
Plugin instances
================
Plugin instances of 0 types found in the database [OK]
The plugins in your database are in good order [OK]
Presence of "copy_relations"
All plugins and page/title extensions have "copy_relations" method if needed. [OK]
PlaceholderField
PlaceholderField configuration okay [OK]
OVERALL RESULTS
9 checks successful!
Installation okay
But when I try running server, I get this thread of errors.
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
July 22, 2022 - 08:47:41
Django version 3.2.14, using settings 'projcms.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\adedi\Documents\Dev\Projects\Django\dj-cms\env\lib\site-packages\django\utils\module_loading.py", line 13, in import_string
module_path, class_name = dotted_path.rsplit('.', 1)
ValueError: not enough values to unpack (expected 2, got 1)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\adedi\Documents\Dev\Projects\Django\dj-cms\env\lib\site-packages\django\core\servers\basehttp.py", line 45, in get_internal_wsgi_application
return import_string(app_path)
File "C:\Users\adedi\Documents\Dev\Projects\Django\dj-cms\env\lib\site-packages\django\utils\module_loading.py", line 17, in import_string
module = import_module(module_path)
File "C:\Users\adedi\AppData\Local\Programs\Python\Python310\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 "C:\Users\adedi\Documents\Dev\Projects\Django\dj-cms\projcms\wsgi.py", line 16, in <module>
application = get_wsgi_application()
File "C:\Users\adedi\Documents\Dev\Projects\Django\dj-cms\env\lib\site-packages\django\core\wsgi.py", line 13, in get_wsgi_application
return WSGIHandler()
File "C:\Users\adedi\Documents\Dev\Projects\Django\dj-cms\env\lib\site-packages\django\core\handlers\wsgi.py", line 127, in __init__
self.load_middleware()
File "C:\Users\adedi\Documents\Dev\Projects\Django\dj-cms\env\lib\site-packages\django\core\handlers\base.py", line 40, in load_middleware
middleware = import_string(middleware_path)
File "C:\Users\adedi\Documents\Dev\Projects\Django\dj-cms\env\lib\site-packages\django\utils\module_loading.py", line 15, in import_string
raise ImportError("%s doesn't look like a module path" % dotted_path) from err
ImportError: djangocms_text_ckeditor doesn't look like a module path
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\adedi\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1009, in _bootstrap_inner
self.run()
File "C:\Users\adedi\AppData\Local\Programs\Python\Python310\lib\threading.py", line 946, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\adedi\Documents\Dev\Projects\Django\dj-cms\env\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "C:\Users\adedi\Documents\Dev\Projects\Django\dj-cms\env\lib\site-packages\django\core\management\commands\runserver.py", line 138, in inner_run
handler = self.get_handler(*args, **options)
File "C:\Users\adedi\Documents\Dev\Projects\Django\dj-cms\env\lib\site-packages\django\contrib\staticfiles\management\commands\runserver.py", line 27, in get_handler
handler = super().get_handler(*args, **options)
File "C:\Users\adedi\Documents\Dev\Projects\Django\dj-cms\env\lib\site-packages\django\core\management\commands\runserver.py", line 65, in get_handler
return get_internal_wsgi_application()
File "C:\Users\adedi\Documents\Dev\Projects\Django\dj-cms\env\lib\site-packages\django\core\servers\basehttp.py", line 47, in get_internal_wsgi_application
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: WSGI application 'projcms.wsgi.application' could not be loaded; Error importing module.
I have inspected my code and can't seem to find any answer.
I have a project of migrating django web app from Django-3.2.14 to Django-4.0. Immediately after migration, when I run the server I get the error as shown in Console output. When I traced the changes, it traced to django-compat package, which was being called by django-background-tasks package. my_env is my virutal environment.
We have latest version of django-compat, which is 1.0.15 and django-background-tasks, which is 1.2.5.
Could you please look into this?
Thank you in advance.
Console:
(myenv) D:\New_Folder\github\project\project_name>python manage.py runserver
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "D:\New_Folder\github\myenv\lib\site-packages\compt\__init__.py", line 46, in <module>
from django.conf.urls import url, include, handler404, handler500
ImportError: cannot import name 'url' from 'django.conf.urls' (D:\New_Folder\github\myenv\lib\site-packages\django\conf\urls\__init__.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\Python39\lib\threading.py", line 980, in _bootstrap_inner
self.run()
File "C:\Program Files\Python39\lib\threading.py", line 917, in run
self._target(*self._args, **self._kwargs)
File "D:\New_Folder\github\myenv\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "D:\New_Folder\github\myenv\lib\site-packages\django\core\management\commands\runserver.py", line 125, in inner_run
autoreload.raise_last_exception()
File "D:\New_Folder\github\myenv\lib\site-packages\django\utils\autoreload.py", line 87, in raise_last_exception
raise _exception[1]
File "D:\New_Folder\github\myenv\lib\site-packages\django\core\management\__init__.py", line 398, in execute
autoreload.check_errors(django.setup)()
File "D:\New_Folder\github\myenv\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "D:\New_Folder\github\myenv\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "D:\New_Folder\github\myenv\lib\site-packages\django\apps\registry.py", line 116, in populate
app_config.import_models()
File "D:\New_Folder\github\myenv\lib\site-packages\django\apps\config.py", line 304, in import_models
self.models_module = import_module(models_module_name)
File "C:\Program Files\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 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "D:\New_Folder\github\myenv\lib\site-packages\background_task\models.py", line 9, in <module>
from compat import StringIO
File "D:\New_Folder\github\myenv\lib\site-packages\compat\__init__.py", line 48, in <module>
from django.conf.urls.defaults import url, include, handler404, handler500 # pyflakes:ignore
ModuleNotFoundError: No module named 'django.conf.urls.defaults'
Updated answer
Sadly there is currently no supported version of django-background-tasks. It seems like you will not be able to upgrade to django 4.0 without migrate to any other package, which will do the same job as django-background-tasks.
https://django-background-tasks.readthedocs.io/en/latest/#supported-versions-and-compatibility
Old Answer
The package background_task is using the django-compat, which is not supported with new django versions.
D:\New_Folder\github\myenv\lib\site-packages\background_task\models.py
from compat import StringIO
As far as I can see in the stacktrace, there is no need to use the django-compat package anymore. The background_task package should use StringIO directly from the default io package.
You will need an updated version of the background_task package, which is not using the django-compat package anymore. As far as I can see there is no new version whithout the dependency.
https://django-background-tasks.readthedocs.io/en/latest/
https://github.com/arteria/django-compat
https://docs.python.org/3/library/io.html#io.StringIO
Django has removed the URL from version 4.0. Check the documentation here:
https://django-background-tasks.readthedocs.io/en/latest/#supported-versions-and-compatibility
Alternatively, you can degrade it back to 3.2.10, which removes the problem
I am trying to Run django-spirit and followed the documentation https://spirit.readthedocs.io/en/latest/installation.html
and using version django-spirit 0.12.3
i followed as bellow
Get started
New in Spirit 0.5
Latest version can be installed through pip:
Install Spirit:
pip install django-spirit
Start your site:
spirit startproject mysite
Set up the database:
cd mysite
python manage.py spiritinstall
Create an administrator account:
python manage.py createsuperuser
python manage.py runserver
python manage.py makermigrations
python manage.py migrate
when i push python manage.py runserver command it thorugh the bellow error.
i have checked out the database too and its empy no tables/database is created
i am using python 3.9 and the requirements versions as per the project requirements
struggling since yesterday but no success
PS C:\Users\gsminfinity.com\Desktop\gsminfinity.com\Spirit-master\community> python manage.py runserver
Performing system checks...
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\gsminfinity.com\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\utils.py", line 66, in __getitem__
return self._engines[alias]
KeyError: 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\gsminfinity.com\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\backends\django.py", line 121, in get_package_libraries
module = import_module(entry[1])
File "C:\Users\gsminfinity.com\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 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:\Users\gsminfinity.com\AppData\Local\Programs\Python\Python39\lib\site-packages\spirit\core\templatetags\spirit_tags.py", line 3, in <module>
from spirit.comment import tags as comment
File "C:\Users\gsminfinity.com\AppData\Local\Programs\Python\Python39\lib\site-packages\spirit\comment\tags.py", line 11, in <module>
from .forms import CommentForm
ImportError: cannot import name 'CommentForm' from partially initialized module 'spirit.comment.forms' (most likely due to a circular import) (C:\Users\gsminfinity.com\AppData\Local\Programs\Python\Python39\lib\site-packages\spirit\comment\forms.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\gsminfinity.com\AppData\Local\Programs\Python\Python39\lib\threading.py", line 950, in _bootstrap_inner
self.run()
File "C:\Users\gsminfinity.com\AppData\Local\Programs\Python\Python39\lib\threading.py", line 888, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\gsminfinity.com\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\gsminfinity.com\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\commands\runserver.py", line 118, in inner_run
self.check(display_num_errors=True)
File "C:\Users\gsminfinity.com\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\base.py", line 392, in check
all_issues = checks.run_checks(
File "C:\Users\gsminfinity.com\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\checks\registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\Users\gsminfinity.com\AppData\Local\Programs\Python\Python39\lib\site-packages\django\contrib\admin\checks.py", line 78, in check_dependencies
for engine in engines.all():
File "C:\Users\gsminfinity.com\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\utils.py", line 90, in all
return [self[alias] for alias in self]
File "C:\Users\gsminfinity.com\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\utils.py", line 90, in <listcomp>
return [self[alias] for alias in self]
File "C:\Users\gsminfinity.com\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\utils.py", line 81, in __getitem__
engine = engine_cls(params)
File "C:\Users\gsminfinity.com\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\backends\django.py", line 25, in __init__
options['libraries'] = self.get_templatetag_libraries(libraries)
File "C:\Users\gsminfinity.com\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\backends\django.py", line 43, in get_templatetag_libraries
libraries = get_installed_libraries()
File "C:\Users\gsminfinity.com\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\backends\django.py", line 108, in get_installed_libraries
for name in get_package_libraries(pkg):
File "C:\Users\gsminfinity.com\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\backends\django.py", line 123, in get_package_libraries
raise InvalidTemplateLibrary(
django.template.library.InvalidTemplateLibrary: Invalid template library specified. ImportError raised when trying to load 'spirit.core.templatetags.spirit_tags': cannot import name 'CommentForm' from partially initialized module 'spirit.comment.forms' (most likely due to a circular import)
(C:\Users\gsminfinity.com\AppData\Local\Programs\Python\Python39\lib\site-packages\spirit\comment\forms.py)
After adding 'rest_framework.authtoken' to INSTALLED_APPS (settings.py) and running python manage.py migrate I started to get a strange error when trying to run django server (the strange thing is, that the error appears on every 2nd or 3rd attempt, sometimes the server starts running without the error):
Watching for file changes with StatReloader
Performing system checks...
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/home/username/.local/share/virtualenvs/blogapi-nhgDNK6P/lib/python3.7/site-packages/django/template/utils.py", line 66, in __getitem__
return self._engines[alias]
KeyError: 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/username/anaconda3/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/home/username/anaconda3/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "/home/username/.local/share/virtualenvs/blogapi-nhgDNK6P/lib/python3.7/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/home/username/.local/share/virtualenvs/blogapi-nhgDNK6P/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "/home/username/.local/share/virtualenvs/blogapi-nhgDNK6P/lib/python3.7/site-packages/django/core/management/base.py", line 390, in check
include_deployment_checks=include_deployment_checks,
File "/home/username/.local/share/virtualenvs/blogapi-nhgDNK6P/lib/python3.7/site-packages/django/core/management/base.py", line 377, in _run_checks
return checks.run_checks(**kwargs)
File "/home/username/.local/share/virtualenvs/blogapi-nhgDNK6P/lib/python3.7/site-packages/django/core/checks/registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "/home/username/.local/share/virtualenvs/blogapi-nhgDNK6P/lib/python3.7/site-packages/django/contrib/admin/checks.py", line 79, in check_dependencies
for engine in engines.all():
File "/home/username/.local/share/virtualenvs/blogapi-nhgDNK6P/lib/python3.7/site-packages/django/template/utils.py", line 90, in all
return [self[alias] for alias in self]
File "/home/username/.local/share/virtualenvs/blogapi-nhgDNK6P/lib/python3.7/site-packages/django/template/utils.py", line 90, in <listcomp>
return [self[alias] for alias in self]
File "/home/username/.local/share/virtualenvs/blogapi-nhgDNK6P/lib/python3.7/site-packages/django/template/utils.py", line 81, in __getitem__
engine = engine_cls(params)
File "/home/username/.local/share/virtualenvs/blogapi-nhgDNK6P/lib/python3.7/site-packages/django/template/backends/django.py", line 25, in __init__
options['libraries'] = self.get_templatetag_libraries(libraries)
File "/home/username/.local/share/virtualenvs/blogapi-nhgDNK6P/lib/python3.7/site-packages/django/template/backends/django.py", line 43, in get_templatetag_libraries
libraries = get_installed_libraries()
File "/home/username/.local/share/virtualenvs/blogapi-nhgDNK6P/lib/python3.7/site-packages/django/template/backends/django.py", line 108, in get_installed_libraries
for name in get_package_libraries(pkg):
File "/home/username/.local/share/virtualenvs/blogapi-nhgDNK6P/lib/python3.7/site-packages/django/template/backends/django.py", line 121, in get_package_libraries
module = import_module(entry[1])
File "/home/username/.local/share/virtualenvs/blogapi-nhgDNK6P/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 "/home/username/.local/share/virtualenvs/blogapi-nhgDNK6P/lib/python3.7/site-packages/rest_framework/templatetags/rest_framework.py", line 12, in <module>
from rest_framework.renderers import HTMLFormRenderer
File "/home/username/.local/share/virtualenvs/blogapi-nhgDNK6P/lib/python3.7/site-packages/rest_framework/renderers.py", line 19, in <module>
from django.test.client import encode_multipart
File "/home/username/.local/share/virtualenvs/blogapi-nhgDNK6P/lib/python3.7/site-packages/django/test/client.py", line 23, in <module>
from django.test import signals
File "<frozen importlib._bootstrap>", line 980, in _find_and_load
File "<frozen importlib._bootstrap>", line 149, in __enter__
File "<frozen importlib._bootstrap>", line 94, in acquire
_frozen_importlib._DeadlockError: deadlock detected by _ModuleLock('django.test.signals') at 139824587568800
I am using: django 2.2.7 and django rest_framework 3.10.3. Thanks for any help.
There's a ticket on Django's issue tracker discussing similar issue: https://code.djangoproject.com/ticket/30352.
For a temporary fix, you can remove all .pyc files on your project and run the runserver command again.
find <path-to-your-project> -type f -name '*.pyc' -delete
NB: I use pyenv which stores the project's virtual environment in a different directory outside the project directory. Removing only the project's .pyc files work for me, but you may also try removing the virtual environment's .pyc files if needed.
For anyone who still gets this error, please kindly comment in the issue page to help Django developers reproduce and fix the error.
I am new to both python and django. I am trying to get python 3.4 and django 1.6.4 working within a pyvenv-3.4 environment on Linux Mint Mate 13. I followed the procedures of Using a virtual environment with Python 3.4 for "Building Python 3.4 from source" and "Using pyvenv-3.4". Then following the Django tutorial at Writing your first Django app, I was able to create "mysite" with startproject. But the command "python manage.py runserver" failed with
django.core.exceptions.
ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules
(tried in that order):
No module named '_sqlite3'
Sorry, I do not recall why I resorted to compiling from source, but it may be that I was unable to find pyvenv in the standard Ubuntu downloads using apt-get. In any case, the Makefile for the source distribution does not have an "uninstall" target, so it seems I am stuck with whatever make installed, and without a plan for what to do next to actually get pyvenv-python-django working.
I am updating this post by attaching the full error:
$ python manage.py runserver
Traceback (most recent call last):
File "/local/djenv/lib/python3.4/site-packages/django/db/backends/sqlite3/base.py", line 30, in <module>
from pysqlite2 import dbapi2 as Database
ImportError: No module named 'pysqlite2'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/local/djenv/lib/python3.4/site-packages/django/db/backends/sqlite3/base.py", line 32, in <module>
from sqlite3 import dbapi2 as Database
File "/usr/local/lib/python3.4/sqlite3/__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "/usr/local/lib/python3.4/sqlite3/dbapi2.py", line 26, in <module>
from _sqlite3 import *
ImportError: No module named '_sqlite3'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/local/djenv/lib/python3.4/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/local/djenv/lib/python3.4/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/local/djenv/lib/python3.4/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/local/djenv/lib/python3.4/site-packages/django/core/management/base.py", line 280, in execute
translation.activate('en-us')
File "/local/djenv/lib/python3.4/site-packages/django/utils/translation/__init__.py", line 130, in activate
return _trans.activate(language)
File "/local/djenv/lib/python3.4/site-packages/django/utils/translation/trans_real.py", line 188, in activate
_active.value = translation(language)
File "/local/djenv/lib/python3.4/site-packages/django/utils/translation/trans_real.py", line 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/local/djenv/lib/python3.4/site-packages/django/utils/translation/trans_real.py", line 159, in _fetch
app = import_module(appname)
File "/usr/local/lib/python3.4/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 "/local/djenv/lib/python3.4/site-packages/django/contrib/admin/__init__.py", line 6, in <module>
from django.contrib.admin.sites import AdminSite, site
File "/local/djenv/lib/python3.4/site-packages/django/contrib/admin/sites.py", line 4, in <module>
from django.contrib.admin.forms import AdminAuthenticationForm
File "/local/djenv/lib/python3.4/site-packages/django/contrib/admin/forms.py", line 6, in <module>
from django.contrib.auth.forms import AuthenticationForm
File "/local/djenv/lib/python3.4/site-packages/django/contrib/auth/forms.py", line 17, in <module>
from django.contrib.auth.models import User
File "/local/djenv/lib/python3.4/site-packages/django/contrib/auth/models.py", line 48, in <module>
class Permission(models.Model):
File "/local/djenv/lib/python3.4/site-packages/django/db/models/base.py", line 96, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "/local/djenv/lib/python3.4/site-packages/django/db/models/base.py", line 264, in add_to_class
value.contribute_to_class(cls, name)
File "/local/djenv/lib/python3.4/site-packages/django/db/models/options.py", line 124, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/local/djenv/lib/python3.4/site-packages/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/local/djenv/lib/python3.4/site-packages/django/db/utils.py", line 198, in __getitem__
backend = load_backend(db['ENGINE'])
File "/local/djenv/lib/python3.4/site-packages/django/db/utils.py", line 113, in load_backend
return import_module('%s.base' % backend_name)
File "/usr/local/lib/python3.4/importlib/__init__.py", line 104, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/local/djenv/lib/python3.4/site-packages/django/db/backends/sqlite3/base.py", line 35, in <module>
raise ImproperlyConfigured("Error loading either pysqlite2 or sqlite3 modules (tried in that order): %s" % exc)
django.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named '_sqlite3'
It sounds like you didn't have the SQLite development libraries installed at the time you built CPython from source. The build process conditionally includes some features based the availability of underlying development libraries.
On Debian GNU/Linux and derivatives, install libsqlite3-dev. Then re-run ./configure, make and make install.