2017-05-27 26 views
0

我試圖配置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的事實是否意義重大?

+0

你是怎麼安裝python-mysql軟件包?我強烈建議在任何系統軟件包上使用virtualenv。激活你的env然後'pip install mysqlclient' –

回答

0

OK,一些插科打諢後,我有各種各樣的答案,雖然不是令人滿意的,因爲我想。

在Python 3.x中不支持MySQLdb庫,因此您應該使用它的mysqlclient分支。然而,因爲我使用的是MySQL的MariaDB的叉子,一些Debian的依賴安裝mysqlclient是未滿足的需要。我不想恢復到MySQL,因爲我正在將MariaDB用於其他目的。因此,儘管我需要的是一個相當健壯的多用戶後端RDBMS,但我已經安裝了PostgreSQL以便與Django一起使用,這似乎很好地工作。

相關問題