我試圖配置Django的運行Python3下的Debian盒使用MariaDB的作爲其後端。如果我改變我的mysite/settpings.py
按照本教程即的MySQL(MariaDB的)Python3下後端Django的Debian的
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'foo',
'USER': 'tim',
'PASSWORD': 'swordfish',
'HOST': 'localhost'
}
}
我得到了很多的悲傷,在
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/mysql/base.py", line 30, in <module>
'Did you install mysqlclient or MySQL-python?' % e
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'.
Did you install mysqlclient or MySQL-python?
高潮現在,很明顯,MySQLdb的不會對Python3工作,雖然我已經安裝了mysql連接器包似乎不起作用。
如果我試圖通過MySQL的
使用連接器recommended即
DATABASES = {
'default': {
'ENGINE': 'mysql.connector.django',
'NAME': 'foo',
'USER': 'tim',
'PASSWORD': 'swordfish',
'HOST': 'localhost'
然後我得到的悲痛中
django.core.exceptions.ImproperlyConfigured: 'mysql.connector.django' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
'mysql', 'oracle', 'postgresql', 'sqlite3'
Error was: cannot import name 'BaseDatabaseFeatures'
任何建議,最終的負擔?
UPDATE
繼馬特·西摩的建議,如果我嘗試畫中畫(PIP 3實際上作爲我的系統Python是仍然2.X)安裝我得到以下的mysqlclient
...
[email protected]:~/mysite$ sudo pip3 install mysqlclient
Collecting mysqlclient
Using cached mysqlclient-1.3.10.tar.gz
Complete output from command python setup.py egg_info:
/bin/sh: 1: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-9uub69zo/mysqlclient/setup.py", line 17, in <module>
metadata, options = get_config()
File "/tmp/pip-build-9uub69zo/mysqlclient/setup_posix.py", line 44, in get_config
libs = mysql_config("libs_r")
File "/tmp/pip-build-9uub69zo/mysqlclient/setup_posix.py", line 26, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
OSError: mysql_config not found
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-9uub69zo/mysqlclient
我在這裏使用MariaDB而不是MySQL的事實是否意義重大?
你是怎麼安裝python-mysql軟件包?我強烈建議在任何系統軟件包上使用virtualenv。激活你的env然後'pip install mysqlclient' –