How to start server with "python manage.py runserver" whithout errors? - python

I installed Django with: conda create --name myproject django
Every check I made (environement, django, versions, etc) seems to be alright and I don't know what the problem is.
What I have:
(myproject) D:\###Work###\###INFORMATICA###\###PYTHON###\MySite>python -V
Python 3.7.3
(myproject) D:\###Work###\###INFORMATICA###\###PYTHON###\MySite>conda -V
conda 4.6.14
(myproject) D:\###Work###\###INFORMATICA###\###PYTHON###\MySite>conda
list
packages in environment at C:\ProgramData\Anaconda3\envs\myproject:
Name Version Build Channel
astroid 2.2.5 py37_0
ca-certificates 2019.1.23 0
certifi 2019.3.9 py37_0
colorama 0.4.1 py37_0
django 2.2 py37_0
isort 4.3.17 py37_0
lazy-object-proxy 1.3.1 py37hfa6e2cd_2
mccabe 0.6.1 py37_1
openssl 1.1.1b he774522_1
pip 19.1 py37_0
pylint 2.3.1 py37_0
python 3.7.3 h8c8aaf0_1
pytz 2019.1 py_0
setuptools 41.0.1 py37_0
six 1.12.0 py37_0
sqlite 3.28.0 he774522_0
vc 14.1 h0510ff6_4
vs2015_runtime 14.15.26706 h3a45250_4
wheel 0.33.1 py37_0
wincertstore 0.2 py37_0
wrapt 1.11.1 py37he774522_0
(myproject) D:\###Work###\###INFORMATICA###\###PYTHON###\MySite> conda
info --envs
conda environments:
base C:\ProgramData\Anaconda3
myproject * C:\ProgramData\Anaconda3\envs\myproject
'# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
And this is the output for : python manage.py runserver
(tried to add an IP and port but still no solution)
(myproject) D:\###Work###\###INFORMATICA###\###PYTHON###\MySite>python manage.py runserver
Watching for file changes with StatReloader Exception in thread Thread-1: Traceback (most recent call last): File "C:\ProgramData\Anaconda3\envs\myproject\lib\threading.py", line 917, in _bootstrap_inner
self.run() File "C:\ProgramData\Anaconda3\envs\myproject\lib\threading.py", line 865, in run
self._target(*self._args, **self._kwargs) File "C:\ProgramData\Anaconda3\envs\myproject\lib\site-packages\django\utils\autoreload.py", line 54, in wrapper
fn(*args, **kwargs) File "C:\ProgramData\Anaconda3\envs\myproject\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception() File "C:\ProgramData\Anaconda3\envs\myproject\lib\site-packages\django\utils\autoreload.py", line 77, in raise_last_exception
raise _exception[0](_exception[1]).with_traceback(_exception[2]) File "C:\ProgramData\Anaconda3\envs\myproject\lib\site-packages\django\utils\autoreload.py", line 54, in wrapper
fn(*args, **kwargs) File "C:\ProgramData\Anaconda3\envs\myproject\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS) File "C:\ProgramData\Anaconda3\envs\myproject\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models() File "C:\ProgramData\Anaconda3\envs\myproject\lib\site-packages\django\apps\config.py", line 211, in import_models
self.models_module = import_module(models_module_name) File "C:\ProgramData\Anaconda3\envs\myproject\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:\ProgramData\Anaconda3\envs\myproject\lib\site-packages\django\contrib\auth\models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager File "C:\ProgramData\Anaconda3\envs\myproject\lib\site-packages\django\contrib\auth\base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model): File "C:\ProgramData\Anaconda3\envs\myproject\lib\site-packages\django\db\models\base.py", line 117, in __new__
new_class.add_to_class('_meta', Options(meta, app_label)) File "C:\ProgramData\Anaconda3\envs\myproject\lib\site-packages\django\db\models\base.py", line 321, in add_to_class
value.contribute_to_class(cls, name) File "C:\ProgramData\Anaconda3\envs\myproject\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:\ProgramData\Anaconda3\envs\myproject\lib\site-packages\django\db\__init__.py", line 28, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item) File "C:\ProgramData\Anaconda3\envs\myproject\lib\site-packages\django\db\utils.py", line 201, in __getitem__
backend = load_backend(db['ENGINE']) File "C:\ProgramData\Anaconda3\envs\myproject\lib\site-packages\django\db\utils.py", line 110, in load_backend
return import_module('%s.base' % backend_name) File "C:\ProgramData\Anaconda3\envs\myproject\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level) File "C:\ProgramData\Anaconda3\envs\myproject\lib\site-packages\django\db\backends\sqlite3\base.py", line 28, in <module>
from .introspection import DatabaseIntrospection # isort:skip File "C:\ProgramData\Anaconda3\envs\myproject\lib\site-packages\django\db\backends\sqlite3\introspection.py", line 4, in <module>
import sqlparse ModuleNotFoundError: No module named 'sqlparse' Traceback (most recent call last): File "C:\ProgramData\Anaconda3\envs\myproject\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 21, in <module>
main() File "manage.py", line 17, in main
execute_from_command_line(sys.argv) File "C:\ProgramData\Anaconda3\envs\myproject\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute() File "C:\ProgramData\Anaconda3\envs\myproject\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\ProgramData\Anaconda3\envs\myproject\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options) File "C:\ProgramData\Anaconda3\envs\myproject\lib\site-packages\django\core\management\commands\runserver.py", line 60, in execute
super().execute(*args, **options) File "C:\ProgramData\Anaconda3\envs\myproject\lib\site-packages\django\core\management\base.py", line 364, in execute
output = self.handle(*args, **options) File "C:\ProgramData\Anaconda3\envs\myproject\lib\site-packages\django\core\management\commands\runserver.py", line 95, in handle
self.run(**options) File "C:\ProgramData\Anaconda3\envs\myproject\lib\site-packages\django\core\management\commands\runserver.py", line 102, in run
autoreload.run_with_reloader(self.inner_run, **options) File "C:\ProgramData\Anaconda3\envs\myproject\lib\site-packages\django\utils\autoreload.py", line 579, in run_with_reloader
start_django(reloader, main_func, *args, **kwargs) File "C:\ProgramData\Anaconda3\envs\myproject\lib\site-packages\django\utils\autoreload.py", line 564, in start_django
reloader.run(django_main_thread) File "C:\ProgramData\Anaconda3\envs\myproject\lib\site-packages\django\utils\autoreload.py", line 272, in run
get_resolver().urlconf_module File "C:\ProgramData\Anaconda3\envs\myproject\lib\site-packages\django\utils\functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance) File "C:\ProgramData\Anaconda3\envs\myproject\lib\site-packages\django\urls\resolvers.py", line 564, in urlconf_module
return import_module(self.urlconf_name) File "C:\ProgramData\Anaconda3\envs\myproject\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:\###Work###\###INFORMATICA###\###PYTHON###\MySite\MySite\urls.py", line 20, in <module>
path('admin/', admin.site.urls), File "C:\ProgramData\Anaconda3\envs\myproject\lib\site-packages\django\utils\functional.py", line 256, in inner
self._setup() File "C:\ProgramData\Anaconda3\envs\myproject\lib\site-packages\django\contrib\admin\sites.py", line 529, in _setup
AdminSiteClass = import_string(apps.get_app_config('admin').default_site) File "C:\ProgramData\Anaconda3\envs\myproject\lib\site->packages\django\apps\registry.py", line 162, in get_app_config
raise LookupError(message) LookupError: No installed app with label 'admin'.
(myproject) D:\###Work###\###INFORMATICA###\###PYTHON###\MySite
What could be the solution to the problem?

I found out an answer.
It seems that conda package manager is not working properly on my windows 10 installation.The solution is to install with pip package manager.
With the virtual environement active the command is:
pip install django --force
Hope that no one will spend so much time, to figure out a verry simple solution.
Ceers!

Related

ImportError raised when trying to load 'rest_framework.templatetags.rest_framework'

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)

Postgresql not working with django on Macos: El Capitan

I installed Postgresql from the official site (version 4.0), I created a database with "pgAdmin 4", and tried to connect my django project to it.
But an error prevented me from the running the django server, the error says:
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/Users/yyy/.local/share/virtualenvs/mysite-G0YpajmP/lib/python3.9/site-packages/django/db/backends/postgresql/base.py", line 25, in <module>
import psycopg2 as Database
File "/Users/yyy/.local/share/virtualenvs/mysite-G0YpajmP/lib/python3.9/site-packages/psycopg2/__init__.py", line 51, in <module>
from psycopg2._psycopg import ( # noqa
ImportError: dlopen(/Users/yyy/.local/share/virtualenvs/mysite-G0YpajmP/lib/python3.9/site-packages/psycopg2/_psycopg.cpython-39-darwin.so, 2): Symbol not found: ____chkstk_darwin
Referenced from: /Users/yyy/.local/share/virtualenvs/mysite-G0YpajmP/lib/python3.9/site-packages/psycopg2/.dylibs/libcrypto.1.1.dylib
Expected in: /usr/lib/libSystem.B.dylib
in /Users/yyy/.local/share/virtualenvs/mysite-G0YpajmP/lib/python3.9/site-packages/psycopg2/.dylibs/libcrypto.1.1.dylib
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 973, in _bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 910, in run
self._target(*self._args, **self._kwargs)
File "/Users/yyy/.local/share/virtualenvs/mysite-G0YpajmP/lib/python3.9/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "/Users/yyy/.local/share/virtualenvs/mysite-G0YpajmP/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 110, in inner_run
autoreload.raise_last_exception()
File "/Users/yyy/.local/share/virtualenvs/mysite-G0YpajmP/lib/python3.9/site-packages/django/utils/autoreload.py", line 76, in raise_last_exception
raise _exception[1]
File "/Users/yyy/.local/share/virtualenvs/mysite-G0YpajmP/lib/python3.9/site-packages/django/core/management/__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "/Users/yyy/.local/share/virtualenvs/mysite-G0YpajmP/lib/python3.9/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "/Users/yyy/.local/share/virtualenvs/mysite-G0YpajmP/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/yyy/.local/share/virtualenvs/mysite-G0YpajmP/lib/python3.9/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/Users/yyy/.local/share/virtualenvs/mysite-G0YpajmP/lib/python3.9/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/Library/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 "/Users/yyy/.local/share/virtualenvs/mysite-G0YpajmP/lib/python3.9/site-packages/django/contrib/auth/models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/Users/yyy/.local/share/virtualenvs/mysite-G0YpajmP/lib/python3.9/site-packages/django/contrib/auth/base_user.py", line 48, in <module>
class AbstractBaseUser(models.Model):
File "/Users/yyy/.local/share/virtualenvs/mysite-G0YpajmP/lib/python3.9/site-packages/django/db/models/base.py", line 122, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/Users/yyy/.local/share/virtualenvs/mysite-G0YpajmP/lib/python3.9/site-packages/django/db/models/base.py", line 326, in add_to_class
value.contribute_to_class(cls, name)
File "/Users/yyy/.local/share/virtualenvs/mysite-G0YpajmP/lib/python3.9/site-packages/django/db/models/options.py", line 206, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/Users/yyy/.local/share/virtualenvs/mysite-G0YpajmP/lib/python3.9/site-packages/django/db/__init__.py", line 28, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/Users/yyy/.local/share/virtualenvs/mysite-G0YpajmP/lib/python3.9/site-packages/django/db/utils.py", line 214, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Users/yyy/.local/share/virtualenvs/mysite-G0YpajmP/lib/python3.9/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.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/Users/yyy/.local/share/virtualenvs/mysite-G0YpajmP/lib/python3.9/site-packages/django/db/backends/postgresql/base.py", line 29, in <module>
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: dlopen(/Users/yyy/.local/share/virtualenvs/mysite-G0YpajmP/lib/python3.9/site-packages/psycopg2/_psycopg.cpython-39-darwin.so, 2): Symbol not found: ____chkstk_darwin
Referenced from: /Users/yyy/.local/share/virtualenvs/mysite-G0YpajmP/lib/python3.9/site-packages/psycopg2/.dylibs/libcrypto.1.1.dylib
Expected in: /usr/lib/libSystem.B.dylib
in /Users/yyy/.local/share/virtualenvs/mysite-G0YpajmP/lib/python3.9/site-packages/psycopg2/.dylibs/libcrypto.1.1.dylib
The django project is created inside a "pipenv" virtual environment with the following pip packages installed:
asgiref 3.4.1
certifi 2021.10.8
charset-normalizer 2.0.7
cPython 0.0.6
Django 3.1.13
idna 3.3
pip 21.2.4
postgres 4.0
psycopg2-binary 2.9.1
psycopg2-pool 1.1
pymongo 3.12.1
pytz 2021.3
requests 2.26.0
setuptools 58.2.0
sqlparse 0.4.2
urllib3 1.26.7
wheel 0.37.0
I tried other solutions but all of them didn't work.
Why doesn't postgresql run probably with django on my machine?
I solved the problem by downloading Anaconda
and xcode for OS X EL CAPITAN 10.11.6 from here
Anaconda has psycopg2 and downloads it without any problems.
Now I have a conda virtual environment with Django + postgresql installed, working perfectly with EL CAPITAN 10.11.6.
Thumbs up for #RichardHuxton comment: the problem was the django project virtual environment.

Django: Why is package not found in virutal environment?

I am currently setting up a simple search in django using the elastic search and haystack packages.
However, when I run the server , it occures the following error:
(development_env) C:\Users\user\Desktop\Development\development>python manage.py runserver
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\user\Desktop\Development\development\development_env\lib\site-packages\django\utils\autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "C:\Users\user\Desktop\Development\development\development_env\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "C:\Users\user\Desktop\Development\development\development_env\lib\site-packages\django\utils\autoreload.py", line 77, in raise_last_exception
raise _exception[1]
File "C:\Users\user\Desktop\Development\development\development_env\lib\site-packages\django\core\management\__init__.py", line 337, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\user\Desktop\Development\development\development_env\lib\site-packages\django\utils\autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "C:\Users\user\Desktop\Development\development\development_env\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\user\Desktop\Development\development\development_env\lib\site-packages\django\apps\registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "C:\Users\user\Desktop\Development\development\development_env\lib\site-packages\django\apps\config.py", line 90, in create
module = import_module(entry)
File "C:\Users\user\AppData\Local\Programs\Python\Python38\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 'elasticsearch-dsl'
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\user\Desktop\Development\development\development_env\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\user\Desktop\Development\development\development_env\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\user\Desktop\Development\development\development_env\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\user\Desktop\Development\development\development_env\lib\site-packages\django\core\management\commands\runserver.py", line 60, in execute
super().execute(*args, **options)
File "C:\Users\user\Desktop\Development\development\development_env\lib\site-packages\django\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "C:\Users\user\Desktop\Development\development\development_env\lib\site-packages\django\core\management\commands\runserver.py", line 95, in handle
self.run(**options)
File "C:\Users\user\Desktop\Development\development\development_env\lib\site-packages\django\core\management\commands\runserver.py", line 102, in run
autoreload.run_with_reloader(self.inner_run, **options)
File "C:\Users\user\Desktop\Development\development\development_env\lib\site-packages\django\utils\autoreload.py", line 598, in run_with_reloader
start_django(reloader, main_func, *args, **kwargs)
File "C:\Users\user\Desktop\Development\development\development_env\lib\site-packages\django\utils\autoreload.py", line 583, in start_django
reloader.run(django_main_thread)
File "C:\Users\user\Desktop\Development\development\development_env\lib\site-packages\django\utils\autoreload.py", line 301, in run
self.run_loop()
File "C:\Users\user\Desktop\Development\development\development_env\lib\site-packages\django\utils\autoreload.py", line 307, in run_loop
next(ticker)
File "C:\Users\user\Desktop\Development\development\development_env\lib\site-packages\django\utils\autoreload.py", line 347, in tick
for filepath, mtime in self.snapshot_files():
File "C:\Users\user\Desktop\Development\development\development_env\lib\site-packages\django\utils\autoreload.py", line 363, in snapshot_files
for file in self.watched_files():
File "C:\Users\user\Desktop\Development\development\development_env\lib\site-packages\django\utils\autoreload.py", line 262, in watched_files
yield from iter_all_python_module_files()
File "C:\Users\user\Desktop\Development\development\development_env\lib\site-packages\django\utils\autoreload.py", line 103, in iter_all_python_module_files
return iter_modules_and_files(modules, frozenset(_error_files))
File "C:\Users\user\Desktop\Development\development\development_env\lib\site-packages\django\utils\autoreload.py", line 139, in iter_modules_and_files
if not path.exists():
File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\pathlib.py", line 1385, in exists
self.stat()
File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\pathlib.py", line 1191, in stat
return self._accessor.stat(self)
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '<frozen importlib._bootstrap>'
I particularly wondering about the error: ModuleNotFoundError: No module named 'elasticsearch-dsl'.
If I check my installed packages, I see that 'elasticsearch-dsl' is installed:
(development_env) C:\Users\user\Desktop\Development\development>pip list
Package Version
------------------------ -------
appdirs 1.4.3
asgiref 3.2.3
distlib 0.3.0
Django 2.2.10
django-crispy-forms 1.8.1
django-elasticsearch-dsl 7.1.1
django-haystack 2.8.1
django-six 1.0.4
elasticsearch 7.5.1
elasticsearch-dsl 7.1.0
filelock 3.0.12
Pillow 7.0.0
pip 19.2.3
python-dateutil 2.8.1
pytz 2019.3
setuptools 41.2.0
six 1.14.0
sqlparse 0.3.0
urllib3 1.25.8
virtualenv 20.0.5
virtualenvwrapper-win 1.2.6
I also checked 'django-elasticsearch-dsl' instead of 'elasticsearch-dsl' but the error code is the same. I seems that the elastic search package is somehow not correctly installed in my virutal environment.
I'm thankful for every hint.
Greetings Daniel
You have to add the package inside of your app/settings.py:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
....
'elasticsearch-dsl'
]
The error should disappear.
Greetings Alex

Problems with mysqlclient in python virtualenv on OSX

I'm trying to make a Django application that uses mysql as database engine. I have followed a tutorial where it says I have to download pymysql packages using pip. I used the next command pip install pymysql. Unitl here all working. The next step is to make migrations in the django project, but when I try to do it, it throws me the next error:
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 "/Users/paulmirve/anaconda3/envs/myDjangoEnv/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/Users/paulmirve/anaconda3/envs/myDjangoEnv/lib/python3.7/site-packages/django/core/management/__init__.py", line 357, in execute
django.setup()
File "/Users/paulmirve/anaconda3/envs/myDjangoEnv/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/paulmirve/anaconda3/envs/myDjangoEnv/lib/python3.7/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/Users/paulmirve/anaconda3/envs/myDjangoEnv/lib/python3.7/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/Users/paulmirve/anaconda3/envs/myDjangoEnv/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/paulmirve/anaconda3/envs/myDjangoEnv/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/paulmirve/anaconda3/envs/myDjangoEnv/lib/python3.7/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "/Users/paulmirve/anaconda3/envs/myDjangoEnv/lib/python3.7/site-packages/django/db/models/base.py", line 117, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/Users/paulmirve/anaconda3/envs/myDjangoEnv/lib/python3.7/site-packages/django/db/models/base.py", line 321, in add_to_class
value.contribute_to_class(cls, name)
File "/Users/paulmirve/anaconda3/envs/myDjangoEnv/lib/python3.7/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 "/Users/paulmirve/anaconda3/envs/myDjangoEnv/lib/python3.7/site-packages/django/db/__init__.py", line 28, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/Users/paulmirve/anaconda3/envs/myDjangoEnv/lib/python3.7/site-packages/django/db/utils.py", line 201, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Users/paulmirve/anaconda3/envs/myDjangoEnv/lib/python3.7/site-packages/django/db/utils.py", line 110, in load_backend
return import_module('%s.base' % backend_name)
File "/Users/paulmirve/anaconda3/envs/myDjangoEnv/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/Users/paulmirve/anaconda3/envs/myDjangoEnv/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 36, in <module>
raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.
It says my mysqlclient is in a older version, and I need to upgrade it, but when I try to install mysqlclient using pip install mysqlclient it throws me the next error:
Collecting mysqlclient
Using cached https://files.pythonhosted.org/packages/f4/f1/3bb6f64ca7a429729413e6556b7ba5976df06019a5245a43d36032f1061e/mysqlclient-1.4.2.post1.tar.gz
ERROR: Complete output from command python setup.py egg_info:
ERROR: /bin/sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/8y/f31pp_9n7qvc6649ltx1fzsw0000gn/T/pip-install-94slmbbk/mysqlclient/setup.py", line 16, in <module>
metadata, options = get_config()
File "/private/var/folders/8y/f31pp_9n7qvc6649ltx1fzsw0000gn/T/pip-install-94slmbbk/mysqlclient/setup_posix.py", line 51, in get_config
libs = mysql_config("libs")
File "/private/var/folders/8y/f31pp_9n7qvc6649ltx1fzsw0000gn/T/pip-install-94slmbbk/mysqlclient/setup_posix.py", line 29, in mysql_config
raise EnvironmentError("%s not found" % (_mysql_config_path,))
OSError: mysql_config not found
----------------------------------------
ERROR: Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/8y/f31pp_9n7qvc6649ltx1fzsw0000gn/T/pip-install-94slmbbk/mysqlclient/
I have tryied using pip install --update mysqlclient but doesn't work either. How can I solve this? I'm using python 3.7.3 and using MacOS Mojave.

Django runserver error, new installation, first time user of Django

So I've decided to learn Django, which will be challenging if I cannot get it working.
Running
Python 3.7.1 (default, Dec 14 2018, 19:28:38)
[GCC 7.3.0] :: Anaconda, Inc. on linux
(base) runout#runout:~$ python -m django --version
2.2.1
I'm following the tutorial for beginners at djangoproject.com
The first line of code was to create a site, which i did...
django-admin startproject mysite
The second line of code, is where I run into problems.
python manage.py runserver
My error is as follows:
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/home/runout/anaconda3/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/home/runout/anaconda3/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "/home/runout/anaconda3/lib/python3.7/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/home/runout/anaconda3/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/home/runout/anaconda3/lib/python3.7/site-packages/django/utils/autoreload.py", line 77, in raise_last_exception
raise _exception[0](_exception[1]).with_traceback(_exception[2])
File "/home/runout/anaconda3/lib/python3.7/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/home/runout/anaconda3/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/runout/anaconda3/lib/python3.7/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/home/runout/anaconda3/lib/python3.7/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/home/runout/anaconda3/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/runout/anaconda3/lib/python3.7/site-packages/django/contrib/auth/models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/home/runout/anaconda3/lib/python3.7/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "/home/runout/anaconda3/lib/python3.7/site-packages/django/db/models/base.py", line 117, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/home/runout/anaconda3/lib/python3.7/site-packages/django/db/models/base.py", line 321, in add_to_class
value.contribute_to_class(cls, name)
File "/home/runout/anaconda3/lib/python3.7/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 "/home/runout/anaconda3/lib/python3.7/site-packages/django/db/__init__.py", line 28, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/home/runout/anaconda3/lib/python3.7/site-packages/django/db/utils.py", line 201, in __getitem__
backend = load_backend(db['ENGINE'])
File "/home/runout/anaconda3/lib/python3.7/site-packages/django/db/utils.py", line 110, in load_backend
return import_module('%s.base' % backend_name)
File "/home/runout/anaconda3/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/home/runout/anaconda3/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py", line 28, in <module>
from .introspection import DatabaseIntrospection # isort:skip
File "/home/runout/anaconda3/lib/python3.7/site-packages/django/db/backends/sqlite3/introspection.py", line 4, in <module>
import sqlparse
ModuleNotFoundError: No module named 'sqlparse'
I know nothing of Django, I'm excited to learn. I've looked all over the net and SO for a solution to this problem to no avail. Can anyone get me up and running?
Apparently a python package is missing. You can install it like this:
pip install sqlparse
You're on Linux so install 'sqlparse' by typing:
pip3 install sqlparse. Also you should call python with python3, so that it's not confused with python2.

Categories

Resources