Django - 安装 mysqlclient 错误:需要 mysqlclient 1.3.13 或更新版本;你有 0.9.3 [英] Django - installing mysqlclient error: mysqlclient 1.3.13 or newer is required; you have 0.9.3

查看:40
本文介绍了Django - 安装 mysqlclient 错误:需要 mysqlclient 1.3.13 或更新版本;你有 0.9.3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我浏览了论坛,但找不到答案,甚至找不到任何相关文档.试图重新创建一个像 www.testandtrack.io 的网站

I've trawled the forums but cannot find an answer or even any documentation on this. Trying to re-create a site like www.testandtrack.io

运行命令:

python manage.py inspectdb

我收到错误:

mysqlclient 1.3.13 or newer is required; you have 0.9.3

我已经尝试了所有建议的修复,包括:- 升级 pip- 使用命令 pip install mysqlclient-1.4.2-cp37-cp37m-win32.whl 安装不同的轮子(32 位而不是 64 位),即 mysqlclient-1.4.2-cp37-cp37m-win32.whl(这在没有一个错误,但没有完成所需的工作!)

I have tried all the suggested fixes including: -upgrading pip -installing a different wheel (32 bit instead of 64), namely mysqlclient-1.4.2-cp37-cp37m-win32.whl with the command pip install mysqlclient-1.4.2-cp37-cp37m-win32.whl (this works fine without an error but doesn't do the job required!)

我的目标是简单地将旧版 mysql 数据库(在 XAMPP 和 myphpadmin 中运行)连接到 Django.我已经按照文档进行操作,但它忽略了安装 mysqlclient 的需要,并且在这一点上卡住了.

My objective is to simply connect a legacy mysql database (running inside of XAMPP and myphpadmin) to Django. I've followed the documentation which misses out the need to install mysqlclient, and have got stuck at this point.

推荐答案

我就是这样解决的.

转到您的 django/db/backends/mysql 安装目录.检查错误消息中的路径.

Go to your django/db/backends/mysql installation dir. Check your path in the error message.

我正在使用 pipenv 所以我的路径是:

I'm using pipenv so my path is:

/home/username/.local/share/virtualenvs/project-env/lib/python3.7/site-packages/django/db/backends/mysql

/home/username/.local/share/virtualenvs/project-env/lib/python3.7/site-packages/django/db/backends/mysql

如果您使用传统的 env,您的路径将是:

If you use traditional env your path would be:

/Lib/site-packages/django/db/base.py

<env_directory_name>/Lib/site-packages/django/db/base.py

打开文件 base.py 并搜索:

Open file base.py and search for:

version = Database.version_info

在 if 和注释行中放入 pass:

Put a pass inside if and comment line:

raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required;你有 %s.% 数据库.版本)

raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.version)

像这样.

if version < (1, 3, 13):
   pass
   '''
   raise ImproperlyConfigured(
       'mysqlclient 1.3.13 or newer is required; you have %s.'
       % Database.__version__
   )
   '''

保存,关闭此文件并打开operations.py.

Save, close this file and open operations.py.

搜索:

query = query.decode(errors='replace')

并将解码更改为编码

query = query.encode(errors='replace')

现在,尝试运行服务器.

Now, try to run the server.

@edit

在得到这个答案之前,我没有找到其他方法来解决它.今天有更好的方法来处理这个问题.这个答案有更好的方法.

Until this answer, I found no other way to solve it. Today there are better ways to deal with this problem. This answer has a better approach.

这篇关于Django - 安装 mysqlclient 错误:需要 mysqlclient 1.3.13 或更新版本;你有 0.9.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆