PyMySQL Python 3 Django VirtualEnv MySQLdb - python

So I had this running yesterday when I was running the virtualenv out of my home directory. I've ran in to this problem a number of times now without a clear answer. I've done a lot of research on this but there seems to be no black and white answer. Today I moved my virtualenv to /usr/local/virtualenvs to better manage my projects and viola, it's broken again. Error loading MySQLdb module: No module named 'MySQLdb' is the bane of my existence right now. I can't seem to fix it this time. I have even tried duplicating what I did back into my home directory and have the very same problem. I haven't deleted any packages from my system. I installed the very same packages in the virtualenv. At this point I'm lost. I've even written down the steps I took from a fresh install to get to a working virtualenv. I certainly don't want to go back to a fresh install. Please help :)
Virtual Environment:
Ubuntu Server 16.04 LTS
python 3.5
django 1.10.2
pymysql 0.7.9
My settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'auth',
'USER': 'user',
'PASSWORD': 'pass',
'HOST': 'localhost',
'PORT': '3306',
},
'cogs': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'cogs',
'USER': 'user',
'PASSWORD': 'pass',
'HOST': 'localhost',
'PORT': '3306',
}
}
Error:
Traceback (most recent call last):
File "/usr/local/virtualenvs/rtservice/serviceenv/lib/python3.5/site-packages/django/db/backends/mysql/base.py", line 25, in <module>
import MySQLdb as Database
ImportError: No module named 'MySQLdb'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/virtualenvs/rtservice/serviceenv/lib/python3.5/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/usr/local/virtualenvs/rtservice/serviceenv/lib/python3.5/site-packages/django/core/management/__init__.py", line 341, in execute
django.setup()
File "/usr/local/virtualenvs/rtservice/serviceenv/lib/python3.5/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/virtualenvs/rtservice/serviceenv/lib/python3.5/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/usr/local/virtualenvs/rtservice/serviceenv/lib/python3.5/site-packages/django/apps/config.py", line 199, in import_models
self.models_module = import_module(models_module_name)
File "/usr/local/virtualenvs/rtservice/serviceenv/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 "/usr/local/virtualenvs/rtservice/serviceenv/lib/python3.5/site-packages/django/contrib/auth/models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/usr/local/virtualenvs/rtservice/serviceenv/lib/python3.5/site-packages/django/contrib/auth/base_user.py", line 52, in <module>
class AbstractBaseUser(models.Model):
File "/usr/local/virtualenvs/rtservice/serviceenv/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 "/usr/local/virtualenvs/rtservice/serviceenv/lib/python3.5/site-packages/django/db/models/base.py", line 316, in add_to_class
value.contribute_to_class(cls, name)
File "/usr/local/virtualenvs/rtservice/serviceenv/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 "/usr/local/virtualenvs/rtservice/serviceenv/lib/python3.5/site-packages/django/db/__init__.py", line 33, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/usr/local/virtualenvs/rtservice/serviceenv/lib/python3.5/site-packages/django/db/utils.py", line 211, in __getitem__
backend = load_backend(db['ENGINE'])
File "/usr/local/virtualenvs/rtservice/serviceenv/lib/python3.5/site-packages/django/db/utils.py", line 115, in load_backend
return import_module('%s.base' % backend_name)
File "/usr/local/virtualenvs/rtservice/serviceenv/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/usr/local/virtualenvs/rtservice/serviceenv/lib/python3.5/site-packages/django/db/backends/mysql/base.py", line 28, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'
Thanks in advance.

Added
try:
import pymysql
pymysql.install_as_MySQLdb()
except ImportError:
pass
to manage.py and wsgi.py
Now working.

Related

Django postgres psycopg2: ImproperlyConfigure even though module installed

I am using Django for the first time but have used PostgreSQL previously. I am trying to follow the official Django tutorial to set up with a database. I have followed everything but I get an error when using the command "python manage.py migrate" that psycopg2 is not found even though I have it
installed.Traceback (most recent call last):
File "/Users/alexanderverheecke/Library/Python/3.9/lib/python/site-packages/django/db/backends/postgresql/base.py", line 24, in <module>
import psycopg2 as Database
ModuleNotFoundError: No module named 'psycopg2'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/alexanderverheecke/Documents/GitHub/mysite/manage.py", line 22, in <module>
main()
File "/Users/alexanderverheecke/Documents/GitHub/mysite/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/Users/alexanderverheecke/Library/Python/3.9/lib/python/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/Users/alexanderverheecke/Library/Python/3.9/lib/python/site-packages/django/core/management/__init__.py", line 420, in execute
django.setup()
File "/Users/alexanderverheecke/Library/Python/3.9/lib/python/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/alexanderverheecke/Library/Python/3.9/lib/python/site-packages/django/apps/registry.py", line 116, in populate
app_config.import_models()
File "/Users/alexanderverheecke/Library/Python/3.9/lib/python/site-packages/django/apps/config.py", line 269, in import_models
self.models_module = import_module(models_module_name)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.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/alexanderverheecke/Library/Python/3.9/lib/python/site-packages/django/contrib/auth/models.py", line 3, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/Users/alexanderverheecke/Library/Python/3.9/lib/python/site-packages/django/contrib/auth/base_user.py", line 49, in <module>
class AbstractBaseUser(models.Model):
File "/Users/alexanderverheecke/Library/Python/3.9/lib/python/site-packages/django/db/models/base.py", line 141, in __new__
new_class.add_to_class("_meta", Options(meta, app_label))
File "/Users/alexanderverheecke/Library/Python/3.9/lib/python/site-packages/django/db/models/base.py", line 369, in add_to_class
value.contribute_to_class(cls, name)
File "/Users/alexanderverheecke/Library/Python/3.9/lib/python/site-packages/django/db/models/options.py", line 231, in contribute_to_class
self.db_table, connection.ops.max_name_length()
File "/Users/alexanderverheecke/Library/Python/3.9/lib/python/site-packages/django/utils/connection.py", line 15, in __getattr__
return getattr(self._connections[self._alias], item)
File "/Users/alexanderverheecke/Library/Python/3.9/lib/python/site-packages/django/utils/connection.py", line 62, in __getitem__
conn = self.create_connection(alias)
File "/Users/alexanderverheecke/Library/Python/3.9/lib/python/site-packages/django/db/utils.py", line 193, in create_connection
backend = load_backend(db["ENGINE"])
File "/Users/alexanderverheecke/Library/Python/3.9/lib/python/site-packages/django/db/utils.py", line 113, in load_backend
return import_module("%s.base" % backend_name)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.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/alexanderverheecke/Library/Python/3.9/lib/python/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: No module named 'psycopg2'
I am using the settings as mentioned in the Django tutorial:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'DatabaseName',
'USER': 'UserName',
'PASSWORD': 'Userpassword',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
I have confirmed that I have the necessary packages installed and in the same location :
pip freeze:
Django==4.1.3
psycopg2==2.9.5
psycopg2-binary==2.9.5
pip show Django/psycopg2/psycopg2-binary:
Django : Location: /opt/homebrew/lib/python3.10/site-packages
Psycopg2: Location: /opt/homebrew/lib/python3.10/site-packages
psycopg2-binary: Location: /opt/homebrew/lib/python3.10/site-packages
It's seems like you use system python for running your migrations. Error traceback contains following path of python binary: "/Users/alexanderverheecke/Library/Python/3.9/...", however in pip show command your python path is "/opt/homebrew/lib/python3.10/".
Actually I don't understand how it's even possible, because first one looks like Windows path and the second one like Linux...
Anyway. Try something of this and run migrate command again:
activate/deactivate virtual environment if you use it
change your OS to the correct one
run pip install again
Make shure command which python(for Linux), gcm python (for Windows) returns the same python path as pip show.

psycopg2 not detected by postgres django

I am using PyCharm on Windows 10 and using Python 3.8 - 64 bit and Django 2.2. pip install psycopg2 successfully installed psycopg2-2.8.5.
My database settings are as follows:
settings.py,
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'my-database',
'USER': 'my-user',
'PASSWORD': 'my-password',
'HOST': 'localhost',
'PORT': '',
}
}
my-user is the user that I am using and my-password is my password. However, python manage.py makemigrations causes a few errors as follows:
Traceback (most recent call last):
File "C:\Users\HP\PycharmProjects\GeoDjango and Leaflet\venv\lib\site-packages\django\db\backends\postgresql\base.py", line 20, in <module>
import psycopg2 as Database
File "C:\Users\HP\PycharmProjects\GeoDjango and Leaflet\venv\lib\site-packages\psycopg2\__init__.py", line 51, in <module>
from psycopg2._psycopg import ( # noqa
ImportError: DLL load failed while importing _psycopg: The specified module could not be found.
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:\Users\HP\PycharmProjects\GeoDjango and Leaflet\venv\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\HP\PycharmProjects\GeoDjango and Leaflet\venv\lib\site-packages\django\core\management\__init__.py", line 357, in execute
django.setup()
File "C:\Users\HP\PycharmProjects\GeoDjango and Leaflet\venv\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\HP\PycharmProjects\GeoDjango and Leaflet\venv\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "C:\Users\HP\PycharmProjects\GeoDjango and Leaflet\venv\lib\site-packages\django\apps\config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\HP\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 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\HP\PycharmProjects\GeoDjango and Leaflet\venv\lib\site-packages\django\contrib\auth\models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "C:\Users\HP\PycharmProjects\GeoDjango and Leaflet\venv\lib\site-packages\django\contrib\auth\base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "C:\Users\HP\PycharmProjects\GeoDjango and Leaflet\venv\lib\site-packages\django\db\models\base.py", line 117, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "C:\Users\HP\PycharmProjects\GeoDjango and Leaflet\venv\lib\site-packages\django\db\models\base.py", line 321, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Users\HP\PycharmProjects\GeoDjango and Leaflet\venv\lib\site-packages\django\db\models\options.py", line 204, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "C:\Users\HP\PycharmProjects\GeoDjango and Leaflet\venv\lib\site-packages\django\db\__init__.py", line 28, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Users\HP\PycharmProjects\GeoDjango and Leaflet\venv\lib\site-packages\django\db\utils.py", line 201, in __getitem__
backend = load_backend(db['ENGINE'])
File "C:\Users\HP\PycharmProjects\GeoDjango and Leaflet\venv\lib\site-packages\django\db\utils.py", line 110, in load_backend
return import_module('%s.base' % backend_name)
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Users\HP\PycharmProjects\GeoDjango and Leaflet\venv\lib\site-packages\django\contrib\gis\db\backends\postgis\base.py", line 2, in <module>
from django.db.backends.postgresql.base import (
File "C:\Users\HP\PycharmProjects\GeoDjango and Leaflet\venv\lib\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: DLL load failed while importing _psycopg: The specified module could not be found.

Getting traceback error on Django installation?

I am trying to get Django going with mySQL. I have started the app I can see all manage.py and other files. and in setting i changed:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'app',
'USERNAME': 'root',
'PASSWORD': 'root',
'HOST': 'localhost',
}
}
I have installed mySQL separately, I have XAMPP I started it but when I run:
python manage.py migrate
I get the following errors:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 15, in <module>
import MySQLdb as Database
ModuleNotFoundError: No module named 'MySQLdb'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py", line 347, in execute
django.setup()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/apps/registry.py", line 112, in populate
app_config.import_models()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/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 "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/contrib/auth/models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/models/base.py", line 114, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/models/base.py", line 315, in add_to_class
value.contribute_to_class(cls, name)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/models/options.py", line 205, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/__init__.py", line 33, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/utils.py", line 202, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/utils.py", line 110, in load_backend
return import_module('%s.base' % backend_name)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 20, in <module>
) from err
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?
I didnt have this problem before, I think there are some different versions of Django or maybe the MySQL giving me problems.
I am using virtualenv and I have gone through many similar problems in Stackoverflow but no luck.
I have ran these commands:
pip install mysqlclient
sudo apt-get install python-mysqldb (command not found)
pip install mysql-python
still getting the same error.
Questions:
How can i remove all old versions of Django?
what is the solution for getting rid of this error?

MySQLdb configuration error while running Python manage.py makemigrations on Windows

I am setting up a web server for Python on Windows. While configuring settings.py, I changed the database to
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'db_name',
'USER' : 'root',
'PASSWORD' : '123456',
'HOST' : 'localhost'
}
}
I ran python manage.py makemigrations for verification of settings. It threw the following error:
Traceback (most recent call last):
File "C:\Python\lib\site-packages\django\db\backends\mysql\base.py", line 25,in <module> import MySQLdb as Database ImportError: No module named 'MySQLdb' During handling of the above exception, another exception occurred:Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "C:\Python\lib\site-packages\django\core\management\__init__.py", line 353, in execute_from_command_line utility.execute()File "C:\Python\lib\site-packages\django\core\management\__init__.py", line 327, in execute django.setup()ile "C:\Python\lib\site-packages\django\__init__.py", line 18, in setup apps.populate(settings.INSTALLED_APPS) File "C:\Python\lib\site-packages\django\apps\registry.py", line 108, in populate app_config.import_models(all_models)File "C:\Python\lib\site-packages\django\apps\config.py", line 202, in import_models self.models_module = import_module(models_module_name)File "C:\Python\lib\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 662, in exec_module File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "C:\Python\lib\site-packages\django\contrib\auth\models.py", line 4, in <module> from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager File "C:\Python\lib\site-packages\django\contrib\auth\base_user.py", line 49,
in <module>class AbstractBaseUser(models.Model):
File "C:\Python\lib\site-packages\django\db\models\base.py", line 108, in __new__ new_class.add_to_class('_meta', Options(meta, app_label))
File "C:\Python\lib\site-packages\django\db\models\base.py", line 307, in add_to_class value.contribute_to_class(cls, name) File "C:\Python\lib\site-packages\django\db\models\options.py", line 263, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length(
))
File "C:\Python\lib\site-packages\django\db\__init__.py", line 36, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Python\lib\site-packages\django\db\utils.py", line 212, in __getitem__
backend = load_backend(db['ENGINE'])
backend = load_backend(db['ENGINE'])
File "C:\Python\lib\site-packages\django\db\utils.py", line 116, in load_backend
return import_module('%s.base' % backend_name)
File "C:\Python\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Python\lib\site-packages\django\db\backends\mysql\base.py", line 28,
in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'
Then I went to the Python 3 package index to install MySQLdb, but I did not find any supporting packages.
I have downloaded the "mysqlclient-1.3.7-cp27-none-win32" from the Python 3 package index. I installed it with pip install package_name. I even tried installing the wheel package before installing it, but nothing is working. How do I connect MySQL on Windows?
This installation error is coming with Python 3.5.1.

Cannot install MySQL 5.5 with django 1.8.2 on Windows 7 64bit

I had MySQL 5.5 installed as part of XAMPP stack on Win7 64bit. I am using python 3.4 and I want to try out Django. So I installed Django using pip from command line and it worked fine with the default sqlite3 db.
To integrate MySQL, I see installed 'mysql-connector-python' using pip. I changed the engine to ''mysql.connector.django'. I changed the settings.py file with the DATABASE settings as follows:
DATABASES = {
'default': {
'ENGINE': 'mysql.connector.django',
'NAME': 'db',
'USER': 'root',
'PASSWORD': '',
}
}
When I check the server, I get the following error:
Traceback (most recent call last):
File "c:\Python34\lib\site-packages\django\db\utils.py", line 111, in load_backend
return import_module('%s.base' % backend_name)
File "c:\Python34\lib\importlib\__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, 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 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "c:\Python34\lib\site-packages\mysql\connector\django\base.py", line 50, in <module>
from django.db.backends import (BaseDatabaseFeatures, BaseDatabaseOperations,
ImportError: cannot import name 'BaseDatabaseFeatures'
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 "c:\Python34\lib\site-packages\django\core\management\__init__.py", line 338, in execute_from_command_line
utility.execute()
File "c:\Python34\lib\site-packages\django\core\management\__init__.py", line 312, in execute
django.setup()
File "c:\Python34\lib\site-packages\django\__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "c:\Python34\lib\site-packages\django\apps\registry.py", line 108, in populate
app_config.import_models(all_models)
File "c:\Python34\lib\site-packages\django\apps\config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "c:\Python34\lib\importlib\__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, 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 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "c:\Python34\lib\site-packages\django\contrib\auth\models.py", line 41, in <module>
class Permission(models.Model):
File "c:\Python34\lib\site-packages\django\db\models\base.py", line 139, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "c:\Python34\lib\site-packages\django\db\models\base.py", line 324, in add_to_class
value.contribute_to_class(cls, name)
File "c:\Python34\lib\site-packages\django\db\models\options.py", line 250, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "c:\Python34\lib\site-packages\django\db\__init__.py", line 36, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "c:\Python34\lib\site-packages\django\db\utils.py", line 240, in __getitem__
backend = load_backend(db['ENGINE'])
File "c:\Python34\lib\site-packages\django\db\utils.py", line 129, in load_backend
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: 'mysql.connector.django' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
'base', 'mysql', 'oracle', 'postgresql_psycopg2', 'sqlite3'
Error was: cannot import name 'BaseDatabaseFeatures'
Found a bug filed here-
https://bugs.mysql.com/bug.php?id=76752
For resolution, it suggests-
Adjust the backend to the changes in Django API. See the release notes for details:
https://docs.djangoproject.com/en/1.8/releases/1.8/#database-backend-api
How do I adjust the backend? I have no idea how to proceed.
Installing from the forked version works.
pip install git+https://github.com/multiplay/mysql-connector-python
From Github repo description this one is
Fork of version 2.0.4 of mysql-connector-python (and probably rebased
at points) until upstream issues are fixed
Got the reference from bug url.
The latest version of mysql-connector-python works with Django 1.8. You can get it from the mysql website.
(version mysql-connector-python-2.1.3)
Install it from the MySQL:
pip install http://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python-2.1.3.tar.gz

Categories