Hello i m new at django. I installed all moduoles from anaconda. Then created a web application with
django-admin startproject
My project crated successfully. No problem
Then i tried to run that project at localhost to see is everything okay or not. And i run that code in command line
python manage.py runserver
And i get that error:
Unhandled exception in thread started by <function check_errors.
<locals>.wrapper at 0x00000221B6D45A60>
Traceback (most recent call last):
File "C:\Users\Sercan\Anaconda3\lib\site-
packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Users\Sercan\Anaconda3\lib\site-
packages\django\core\management\commands\runserver.py", line 109, in
inner_run
autoreload.raise_last_exception()
File "C:\Users\Sercan\Anaconda3\lib\site-
packages\django\utils\autoreload.py", line 248, in raise_last_exception
raise _exception[1]
File "C:\Users\Sercan\Anaconda3\lib\site-
packages\django\core\management\__init__.py", line 337, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\Sercan\Anaconda3\lib\site-
packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Users\Sercan\Anaconda3\lib\site-packages\django\__init__.py",
line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Sercan\Anaconda3\lib\site-
packages\django\apps\registry.py", line 112, in populate
app_config.import_models()
File "C:\Users\Sercan\Anaconda3\lib\site-packages\django\apps\config.py",
line 198, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\Sercan\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\Sercan\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\Sercan\Anaconda3\lib\site-
packages\django\contrib\auth\base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "C:\Users\Sercan\Anaconda3\lib\site-
packages\django\db\models\base.py", line 101, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "C:\Users\Sercan\Anaconda3\lib\site-
packages\django\db\models\base.py", line 305, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Users\Sercan\Anaconda3\lib\site-
packages\django\db\models\options.py", line 203, in contribute_to_class
self.db_table = truncate_name(self.db_table,
connection.ops.max_name_length())
File "C:\Users\Sercan\Anaconda3\lib\site-packages\django\db\__init__.py",
line 33, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Users\Sercan\Anaconda3\lib\site-packages\django\db\utils.py",
line 202, in __getitem__
backend = load_backend(db['ENGINE'])
File "C:\Users\Sercan\Anaconda3\lib\site-packages\django\db\utils.py",
line 110, in load_backend
return import_module('%s.base' % backend_name)
File "C:\Users\Sercan\Anaconda3\lib\importlib\__init__.py", line 127, in
import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Users\Sercan\Anaconda3\lib\site-
packages\django\db\backends\sqlite3\base.py", line 10, in <module>
from sqlite3 import dbapi2 as Database
File "C:\Users\Sercan\Anaconda3\lib\sqlite3\__init__.py", line 23, in
<module>
from sqlite3.dbapi2 import *
File "C:\Users\Sercan\Anaconda3\lib\sqlite3\dbapi2.py", line 27, in
<module>
from _sqlite3 import *
ImportError: DLL load failed: The specified module could not be found.
Can someone tell me where do i make mistake and how can i fix this problem ?
I had this problem. I solved it by running it in the Anaconda shell.
Open Anaconda Shell/terminal by pressing your Windows key and searching Anaconda
Go to the directory you have your django project in
python manage.py runserver
It sounds like you need to install SQLite:
https://www.sqlite.org/download.html
Or you could change the database settings in your settings file to use some other database.
if you want to use anaconda then follow below steps
conda create --name MyDjangoEnv(virtual environment) Django
press y to install. before press y please make sure correct version of software are selected
activate myDjangoEnv
conda info --envs
conda install django
conda install sqlparse
django-admin startproject first_project
Remove anaconda
Download and install from python.org in c:\python37. Here it will be easy to set variables
Setup python variables
Don't forget to select pip while installing python.
Path:c:\python37,c:\python32\Scripts
If you want to install django on a virtual environment install virtualevmwrapper-win
Voila! It works for me.
I found a solution in this site: http://felipegalvao.com.br/blog/2017/01/03/como-criar-ambientes-e-instalar-o-django-com-distribuicao-anaconda/
Basically, you need to activate an environment in your anaconda prompt.
Step 1: conda info --envs
Step 2 : conda create --name env_name python=3
Step 3: pip install django
Step 4: Assuming that you already created a startproject, run the manage.py runserver
Thanks!
I was facing the same problem, it simply means that dll module is not installed in that path while creating a project don't go with first option i.e venv(virtual environment) this will not let modules to import in your project.., go with the second option for interpreter and select your respective python.exe.
run the below commands in terminal
django-admin
if it shows error then
pip install django
thanks.
Related
I am use django to build the project, when I run python manage.py makemigrations it get the error message:
Traceback (most recent call last):
File "/Users/mingzhe/Desktop/webapp/electric/env/lib/python3.10/site-packages/django/db/backends/postgresql/base.py", line 24, in <module>
import psycopg2 as Database
File "/Users/mingzhe/Desktop/webapp/electric/env/lib/python3.10/site-packages/psycopg2/__init__.py", line 51, in <module>
from psycopg2._psycopg import ( # noqa
ImportError: dlopen(/Users/mingzhe/Desktop/webapp/electric/env/lib/python3.10/site-packages/psycopg2/_psycopg.cpython-310-darwin.so, 0x0002): symbol not found in flat namespace '_PQbackendPID'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/mingzhe/Desktop/webapp/electric/electric/manage.py", line 22, in <module>
main()
File "/Users/mingzhe/Desktop/webapp/electric/electric/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/Users/mingzhe/Desktop/webapp/electric/env/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/Users/mingzhe/Desktop/webapp/electric/env/lib/python3.10/site-packages/django/core/management/__init__.py", line 420, in execute
django.setup()
File "/Users/mingzhe/Desktop/webapp/electric/env/lib/python3.10/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/mingzhe/Desktop/webapp/electric/env/lib/python3.10/site-packages/django/apps/registry.py", line 116, in populate
app_config.import_models()
File "/Users/mingzhe/Desktop/webapp/electric/env/lib/python3.10/site-packages/django/apps/config.py", line 269, in import_models
self.models_module = import_module(models_module_name)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/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 "/Users/mingzhe/Desktop/webapp/electric/env/lib/python3.10/site-packages/django/contrib/auth/models.py", line 3, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/Users/mingzhe/Desktop/webapp/electric/env/lib/python3.10/site-packages/django/contrib/auth/base_user.py", line 49, in <module>
class AbstractBaseUser(models.Model):
File "/Users/mingzhe/Desktop/webapp/electric/env/lib/python3.10/site-packages/django/db/models/base.py", line 141, in __new__
new_class.add_to_class("_meta", Options(meta, app_label))
File "/Users/mingzhe/Desktop/webapp/electric/env/lib/python3.10/site-packages/django/db/models/base.py", line 369, in add_to_class
value.contribute_to_class(cls, name)
File "/Users/mingzhe/Desktop/webapp/electric/env/lib/python3.10/site-packages/django/db/models/options.py", line 231, in contribute_to_class
self.db_table, connection.ops.max_name_length()
File "/Users/mingzhe/Desktop/webapp/electric/env/lib/python3.10/site-packages/django/utils/connection.py", line 15, in __getattr__
return getattr(self._connections[self._alias], item)
File "/Users/mingzhe/Desktop/webapp/electric/env/lib/python3.10/site-packages/django/utils/connection.py", line 62, in __getitem__
conn = self.create_connection(alias)
File "/Users/mingzhe/Desktop/webapp/electric/env/lib/python3.10/site-packages/django/db/utils.py", line 193, in create_connection
backend = load_backend(db["ENGINE"])
File "/Users/mingzhe/Desktop/webapp/electric/env/lib/python3.10/site-packages/django/db/utils.py", line 113, in load_backend
return import_module("%s.base" % backend_name)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/Users/mingzhe/Desktop/webapp/electric/env/lib/python3.10/site-packages/django/db/backends/postgresql/base.py", line 28, in <module>
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: dlopen(/Users/mingzhe/Desktop/webapp/electric/env/lib/python3.10/site-packages/psycopg2/_psycopg.cpython-310-darwin.so, 0x0002): symbol not found in flat namespace '_PQbackendPID'
I already create virtualenv here is my step:
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ brew update
$ brew install postgresql
$ brew services start postgresql
$ virtualenv env
$ source env/bin/activate
(env) $ pip install django psycopg2-binary
I has been used most people's solution: install psycopg2-binary not psycopg2 but still get symbol not found in flat namespace '_PQbackendPID'
My system environment:
macOS Monterey
Python3.10.7 64bit
asgiref==3.5.2
Django==4.1.1
psycopg2-binary==2.9.3
sqlparse==0.4.2
I has try to brew uninstall postgresql and install again it still have same issue, I'm afraid I'm doing something wrong or maybe I don't get how it work on Macbook M1.
Any help or explanation is welcome! Thank you.
try this
pip3 install psycopg2-binary --no-cache-dir
pip uninstall psycopg2
pip install psycopg2-binary --no-cache-dir
C:\Users\SRIRAM_CHIVO\AppData\Local\Programs\Python\Python38\Scripts\FirstDjango
Proj>python manage.py runserver
Exception ignored in thread started by: <function check_errors.<locals>.wrapper
at 0x00000000038D00D0>
Traceback (most recent call last):
File "C:\Users\SRIRAM_CHIVO\AppData\Local\Programs\Python\Python38\lib\site-pa
ckages\django\utils\autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "C:\Users\SRIRAM_CHIVO\AppData\Local\Programs\Python\Python38\lib\site-pa
ckages\django\core\management\commands\runserver.py", line 117, in inner_run
autoreload.raise_last_exception()
File "C:\Users\SRIRAM_CHIVO\AppData\Local\Programs\Python\Python38\lib\site-pa
ckages\django\utils\autoreload.py", line 251, in raise_last_exception
six.reraise(*_exception)
File "C:\Users\SRIRAM_CHIVO\AppData\Local\Programs\Python\Python38\lib\site-pa
ckages\django\utils\six.py", line 685, in reraise
raise value.with_traceback(tb)
File "C:\Users\SRIRAM_CHIVO\AppData\Local\Programs\Python\Python38\lib\site-pa
ckages\django\utils\autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "C:\Users\SRIRAM_CHIVO\AppData\Local\Programs\Python\Python38\lib\site-pa
ckages\django\__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\SRIRAM_CHIVO\AppData\Local\Programs\Python\Python38\lib\site-pa
ckages\django\apps\registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "C:\Users\SRIRAM_CHIVO\AppData\Local\Programs\Python\Python38\lib\site-pa
ckages\django\apps\config.py", line 94, in create
module = import_module(entry)
File "C:\Users\SRIRAM_CHIVO\AppData\Local\Programs\Python\Python38\lib\importl
ib\__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:\Users\SRIRAM_CHIVO\AppData\Local\Programs\Python\Python38\lib\site-pa
ckages\django\contrib\admin\__init__.py", line 4, in <module>
from django.contrib.admin.filters import (
File "C:\Users\SRIRAM_CHIVO\AppData\Local\Programs\Python\Python38\lib\site-pa
ckages\django\contrib\admin\filters.py", line 10, in <module>
from django.contrib.admin.options import IncorrectLookupParameters
File "C:\Users\SRIRAM_CHIVO\AppData\Local\Programs\Python\Python38\lib\site-pa
ckages\django\contrib\admin\options.py", line 12, in <module>
from django.contrib.admin import helpers, widgets
SyntaxError: Generator expression must be parenthesized (widgets.py, line 152)
Django version installed successfully-1.11.10
python version-3.8.1
Project created and manage.py as well created.
BUt while i am trying runserver,Throwing an error with this this big passage:
Help me out how can i solve this?
The same happened with me also, but this issue is a minor one as it happens if you have multiple versions of Python on your system, you can select a specific Python version by running python3 or whichever version you want. So you should start from the beginning, uninstall Django first, then create a virtual environment, decide upon a directory where you want to place it, and run the venv module as a script with the directory path:
python3 -m venv tutorial-env
This will create the tutorial-env directory if it doesn’t exist, and also create directories inside it Once you’ve created a virtual environment, you may activate it.
On Windows, run:
tutorial-env\Scripts\activate.bat
On Unix or MacOS, run:
source tutorial-env/bin/activate
Now, In the command prompt, ensure your virtual environment is active, and execute the following command:
py -m pip install Django
NOTE: If django-admin only displays the help text no matter what arguments it is given, there is probably a problem with the file association in Windows. Check if there is more than one environment variable set for running Python scripts in PATH. This usually occurs when there is more than one Python version installed.
Im trying to start a django project from scratch but i have an error that says "ImportError: No Module Named 'pysqlite2'"
I'm using Python 3.6.0. I will write steps which im following
Creating project
> django-admin startproject testproject
Trying to start an app
> python manage.py startapp demo
Immediately after enters that command, it returns me a long text which includes error's path etc.
Traceback (most recent call last):
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 34, in <module>
from pysqlite2 import dbapi2 as Database
ModuleNotFoundError: No module named 'pysqlite2'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 36, in <module>
from sqlite3 import dbapi2 as Database
File "/usr/local/lib/python3.6/sqlite3/__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "/usr/local/lib/python3.6/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 341, in execute
django.setup()
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/apps/config.py", line 199, in import_models
self.models_module = import_module(models_module_name)
File "/home/berkin/pythonenv/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/contrib/auth/models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/contrib/auth/base_user.py", line 52, in <module>
class AbstractBaseUser(models.Model):
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/db/models/base.py", line 119, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/db/models/base.py", line 316, in add_to_class
value.contribute_to_class(cls, name)
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/db/models/options.py", line 214, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/db/__init__.py", line 33, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/db/utils.py", line 211, in __getitem__
backend = load_backend(db['ENGINE'])
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/db/utils.py", line 115, in load_backend
return import_module('%s.base' % backend_name)
File "/home/berkin/pythonenv/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 39, 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'
What i tried?
- I installed sqlite3-dev with using sudo apt get ...
- I tried to install pip install pysqlite2
- I tried to alter source.py which is inside the virtual env folder but it wasnt worked.
But i figured out that when im not using virtual env, i mean without entering source /bin/activate, "python manage.py startapp demo" command has worked. When i activate env, it returns an error which i mentioned above.
according to this answer https://stackoverflow.com/a/23414147/2174832
There is no public version of pysqlite for Python 3.x. For Python 3.x,
the sqlite3 module in the standard library is the most up-to date
version of pysqlite there is.
run the command pip install sqlite3 within your activated virtualenv and use this module instead of pysqlite2. To activate your virtualenv go to /folderofvirtualenv/bin
and run the command source activate
I'm trying to set up a Django app using a postgresql server (to eventually use with GeoDjango for GIS). I'm on a mac running OSX 10.11 and am running python 3.5 in a virtualenv. I've gone through all the installtion of postgresql, pyscopg2 etc and am trying to run
python manage.py migrate
But when I do I get the following error.
Traceback (most recent call last):
File "/Users/me/.python3env/lib/python3.5/site-packages/django/db/backends/postgresql/base.py", line 20, in <module>
import psycopg2 as Database
File "/Users/me/.python3env/lib/python3.5/site-packages/psycopg2/__init__.py", line 50, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: dlopen(/Users/me/.python3env/lib/python3.5/site-packages/psycopg2/_psycopg.cpython-35m-darwin.so, 2): Library not loaded: libssl.1.0.0.dylib
Referenced from: /Users/me/.python3env/lib/python3.5/site-packages/psycopg2/_psycopg.cpython-35m-darwin.so
Reason: image not found
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/Users/me/.python3env/lib/python3.5/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/Users/me/.python3env/lib/python3.5/site-packages/django/core/management/__init__.py", line 341, in execute
django.setup()
File "/Users/me/.python3env/lib/python3.5/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/me/.python3env/lib/python3.5/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/Users/me/.python3env/lib/python3.5/site-packages/django/apps/config.py", line 199, in import_models
self.models_module = import_module(models_module_name)
File "/Users/me/.python3env/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/Users/me/.python3env/lib/python3.5/site-packages/django/contrib/auth/models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/Users/me/.python3env/lib/python3.5/site-packages/django/contrib/auth/base_user.py", line 52, in <module>
class AbstractBaseUser(models.Model):
File "/Users/me/.python3env/lib/python3.5/site-packages/django/db/models/base.py", line 119, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/Users/me/.python3env/lib/python3.5/site-packages/django/db/models/base.py", line 316, in add_to_class
value.contribute_to_class(cls, name)
File "/Users/me/.python3env/lib/python3.5/site-packages/django/db/models/options.py", line 214, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/Users/me/.python3env/lib/python3.5/site-packages/django/db/__init__.py", line 33, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/Users/me/.python3env/lib/python3.5/site-packages/django/db/utils.py", line 211, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Users/me/.python3env/lib/python3.5/site-packages/django/db/utils.py", line 115, in load_backend
return import_module('%s.base' % backend_name)
File "/Users/me/.python3env/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/Users/me/.python3env/lib/python3.5/site-packages/django/db/backends/postgresql/base.py", line 24, in <module>
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: dlopen(/Users/me/.python3env/lib/python3.5/site-packages/psycopg2/_psycopg.cpython-35m-darwin.so, 2): Library not loaded: libssl.1.0.0.dylib
Referenced from: /Users/me/.python3env/lib/python3.5/site-packages/psycopg2/_psycopg.cpython-35m-darwin.so
Reason: image not found
I've found a couple of stackoverflow threads on this error but none of the solutions seem to help at all.
Any advice would be much appreciated!
Edit: brew doctor output
Warning: python is symlinked to python3
This will confuse build scripts and in general lead to subtle breakage.
Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and what additional flags to use when
compiling and linking.
Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew provided
script of the same name. We found the following "config" scripts:
/Users/me/.python3env/bin/python-config
Warning: Python is installed at /Library/Frameworks/Python.framework
Homebrew only supports building against the System-provided Python or a
brewed Python. In particular, Pythons installed to /Library can interfere
with other software installs.
I want to use Django (using Python 3) with MySQL. To do so, I installed mysqlclient. To first test the waters with MySQL, I also created a new Django project and app, changed the DATABASES configuration in "settings.py" to settings I prepared in MySQL, and ensured that MySQL server is running (the database I created for testing does not have any tables within it at this point).
But when I do
python manage.py runserver
in terminal command, I get the following error:
ImportError: No module named '_mysql_exceptions'
ImportError: No module named '_mysql_exceptions'
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x103efaea0>
Traceback (most recent call last):
File "/Users/shtryts/Django-1.10.1/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Users/shtryts/Django-1.10.1/django/core/management/commands/runserver.py", line 113, in inner_run
autoreload.raise_last_exception()
File "/Users/shtryts/Django-1.10.1/django/utils/autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
File "/Users/shtryts/Django-1.10.1/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/Users/shtryts/Django-1.10.1/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Users/shtryts/Django-1.10.1/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/shtryts/Django-1.10.1/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/Users/shtryts/Django-1.10.1/django/apps/config.py", line 199, in import_models
self.models_module = import_module(models_module_name)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/Users/shtryts/Django-1.10.1/django/contrib/auth/models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/Users/shtryts/Django-1.10.1/django/contrib/auth/base_user.py", line 52, in <module>
class AbstractBaseUser(models.Model):
File "/Users/shtryts/Django-1.10.1/django/db/models/base.py", line 119, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/Users/shtryts/Django-1.10.1/django/db/models/base.py", line 316, in add_to_class
value.contribute_to_class(cls, name)
File "/Users/shtryts/Django-1.10.1/django/db/models/options.py", line 214, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/Users/shtryts/Django-1.10.1/django/db/__init__.py", line 36, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/Users/shtryts/Django-1.10.1/django/db/utils.py", line 211, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Users/shtryts/Django-1.10.1/django/db/utils.py", line 115, in load_backend
return import_module('%s.base' % backend_name)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/Users/shtryts/Django-1.10.1/django/db/backends/mysql/base.py", line 31, in <module>
from MySQLdb.converters import Thing2Literal, conversions # isort:skip
File "/Users/shtryts/.virtualenvs/django/lib/python3.5/site-packages/MySQLdb/converters.py", line 35, in <module>
from _mysql import string_literal, escape_sequence, escape_dict, escape, NULL
ImportError: cannot import name 'NULL'
Should I be modifying a .py file within MySQLdb folder? If so, what should I do so that the Django project properly connects with the database?
I'm testing in a virtualenv, Mac OS X 10.10.3. Thanks in advance for the help. (Also, I did not find a similar question as mine, but apologies if this has been addressed here before).
EDIT: I failed to share my DATABASE setting, so here it is.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'test1',
'USER': 'admin',
'PASSWORD': 'dbadmin',
'HOST': 'localhost',
'PORT': '3306',
}
}
Settings.py, the django project I created for testing purposes, mysqlclient installs, django framework, they're all inside virtualenv. Originally, mysqlclient (includes MySQLdb) was installed via "pip install" under the path /Library/Frameworks/Python.framework/Versions/3.5... I made a copy of the installed folders and placed them under the python site-package folder within virtualenv. From what I understand Django does not have a problem locating those folders and files.
which pip output: /Users/shtryts/.virtualenvs/django/bin/pip. And my own code is in .virtualenvs/django/test/mySQLtest
Ok, there are several problems here.
First of all you cannot copy files from one python installation or virtual installation to another python installation or virtualenv. Please delete your current virtualenv and make a new one, detailed instructions are here: http://docs.python-guide.org/en/latest/dev/virtualenvs/
but briefly
rm -rf /Users/shtryts/.virtualenvs/django
virtualenv /Users/shtryts/.virtualenvs/myvirtualenv
I recommend not using django as the name of the virtualenv. Use a name that shows which version of python is being used. Now activate the virtualenv before going to the next step.
Then you should install all the requirements with pip such as
pip install django
Please note that 'MysqlDB' is not compatible with python 3x please see here for details: https://docs.djangoproject.com/en/1.10/ref/databases/#mysql-db-api-drivers
Last but not least. one does not put one's own code inisde the django installation folders. instead in your home or workspace
django-admin starproject myproject