将MariaDB与Django 1.10和Python 3.5结合使用

问题描述 投票:2回答:1

我想将我的数据库从SQLite迁移到MariaDB。运行Ubuntu 14.04,Django 1.10和Python 3.5。 Digital Ocean has a guide,但它默默地假设一个使用Python 2.x,而不是3.x.他们使用默认的mySQL连接器MySQLdb。这对python 3.x不起作用。 According to Django docs,首选的替代方案是mysqlsclient:

pip install mysqlclient

但这给了:

Collecting mysqlclient
  Using cached mysqlclient-1.3.9.tar.gz
Building wheels for collected packages: mysqlclient
  Running setup.py bdist_wheel for mysqlclient ... error
  Complete output from command /django/env/bin/python3.5 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-3_5btd8o/mysqlclient/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d /tmp/tmp39x31avopip-wheel- --python-tag cp35:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.5
  copying _mysql_exceptions.py -> build/lib.linux-x86_64-3.5
  creating build/lib.linux-x86_64-3.5/MySQLdb
  copying MySQLdb/__init__.py -> build/lib.linux-x86_64-3.5/MySQLdb
  copying MySQLdb/compat.py -> build/lib.linux-x86_64-3.5/MySQLdb
  copying MySQLdb/converters.py -> build/lib.linux-x86_64-3.5/MySQLdb
  copying MySQLdb/connections.py -> build/lib.linux-x86_64-3.5/MySQLdb
  copying MySQLdb/cursors.py -> build/lib.linux-x86_64-3.5/MySQLdb
  copying MySQLdb/release.py -> build/lib.linux-x86_64-3.5/MySQLdb
  copying MySQLdb/times.py -> build/lib.linux-x86_64-3.5/MySQLdb
  creating build/lib.linux-x86_64-3.5/MySQLdb/constants
  copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-3.5/MySQLdb/constants
  copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-3.5/MySQLdb/constants
  copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-3.5/MySQLdb/constants
  copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-3.5/MySQLdb/constants
  copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-3.5/MySQLdb/constants
  copying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-3.5/MySQLdb/constants
  copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-3.5/MySQLdb/constants
  running build_ext
  building '_mysql' extension
  creating build/temp.linux-x86_64-3.5
  x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -Dversion_info=(1,3,9,'final',1) -D__version__=1.3.9 -I/usr/include/mysql -I/usr/include/python3.5m -I/django/env/include/python3.5m -c _mysql.c -o build/temp.linux-x86_64-3.5/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -g -DNDEBUG
  _mysql.c:40:20: fatal error: Python.h: No such file or directory
   #include "Python.h"
                      ^
  compilation terminated.
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for mysqlclient
  Running setup.py clean for mysqlclient
Failed to build mysqlclient
Installing collected packages: mysqlclient
  Running setup.py install for mysqlclient ... error
    Complete output from command /django/env/bin/python3.5 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-3_5btd8o/mysqlclient/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-qfim2s5n-record/install-record.txt --single-version-externally-managed --compile --install-headers /django/env/include/site/python3.5/mysqlclient:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.5
    copying _mysql_exceptions.py -> build/lib.linux-x86_64-3.5
    creating build/lib.linux-x86_64-3.5/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.linux-x86_64-3.5/MySQLdb
    copying MySQLdb/compat.py -> build/lib.linux-x86_64-3.5/MySQLdb
    copying MySQLdb/converters.py -> build/lib.linux-x86_64-3.5/MySQLdb
    copying MySQLdb/connections.py -> build/lib.linux-x86_64-3.5/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.linux-x86_64-3.5/MySQLdb
    copying MySQLdb/release.py -> build/lib.linux-x86_64-3.5/MySQLdb
    copying MySQLdb/times.py -> build/lib.linux-x86_64-3.5/MySQLdb
    creating build/lib.linux-x86_64-3.5/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-3.5/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-3.5/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-3.5/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-3.5/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-3.5/MySQLdb/constants
    copying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-3.5/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-3.5/MySQLdb/constants
    running build_ext
    building '_mysql' extension
    creating build/temp.linux-x86_64-3.5
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -Dversion_info=(1,3,9,'final',1) -D__version__=1.3.9 -I/usr/include/mysql -I/usr/include/python3.5m -I/django/env/include/python3.5m -c _mysql.c -o build/temp.linux-x86_64-3.5/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -g -DNDEBUG
    _mysql.c:40:20: fatal error: Python.h: No such file or directory
     #include "Python.h"
                        ^
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

    ----------------------------------------
Command "/django/env/bin/python3.5 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-3_5btd8o/mysqlclient/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-qfim2s5n-record/install-record.txt --single-version-externally-managed --compile --install-headers /django/env/include/site/python3.5/mysqlclient" failed with error code 1 in /tmp/pip-build-3_5btd8o/mysqlclient/

不确定为什么它部分重复。

根据this question,这种x86_64-linux-gnu-gcc错误的解决方案是安装:

sudo apt install libpq-dev python-dev libxml2-dev libxslt1-dev libldap2-dev libsasl2-dev libffi-dev

我做了,但没有区别。

然后我尝试了其他一些东西,包括:

sudo apt-get install libmysqlclient-dev python-dev

这给了:

libmysqlclient-dev : Depends: libmysqlclient18 (= 5.5.52-0ubuntu0.14.04.1) but 5.5.52+maria-1~trusty is to be installed
E: Unable to correct problems, you have held broken packages.

我发现an answer,据说aptitudeapt-get更有用,并且可以看到一个包含的包列表:

dpkg --get-selections | grep hold

但是在运行它时没有返回任何内容。尝试能力给出:

(env) user@computer:/$ sudo aptitude install libmysqlclient-dev
The following NEW packages will be installed:
  libmysqlclient-dev{b} 
0 packages upgraded, 1 newly installed, 0 to remove and 179 not upgraded.
Need to get 0 B/866 kB of archives. After unpacking 5,604 kB will be used.
The following packages have unmet dependencies:
 libmariadbclient-dev : Conflicts: libmysqlclient-dev but 5.5.52-0ubuntu0.14.04.1 is to be installed.
                        Conflicts: libmysqlclient15-dev which is a virtual package.
 libmysqlclient-dev : Depends: libmysqlclient18 (= 5.5.52-0ubuntu0.14.04.1) but 5.5.52+maria-1~trusty is installed.
The following actions will resolve these dependencies:

     Keep the following packages at their current version:
1)     libmysqlclient-dev [Not Installed] 

它看起来像mysql和基于mariaDB的包之间的冲突。所以我找到了:

pip install libmariadbclient-dev

哪个安装很好,但在尝试安装mysqlclient时仍然存在错误。

如何让MariaDB与Django 1.10和Python 3.5一起使用?

python django ubuntu mariadb
1个回答
0
投票

我在执行时遇到了同样的问题

pip install mysqlclient

然后我发现我必须安装python3-dev软件包,但是他们正在解析为python3.6而我在我的virtualenv中使用了python3.4。

我所要做的就是:

sudo apt-get install python3.4-dev
© www.soinside.com 2019 - 2024. All rights reserved.