MySQL Django - 安装 mysqlclient 错误:需要 mysqlclient 1.3.13 或更新版本;你有 0.9.3
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/55657752/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Django - installing mysqlclient error: mysqlclient 1.3.13 or newer is required; you have 0.9.3
提问by MissComputing
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
我已经搜索了论坛,但找不到答案,甚至找不到任何有关此的文档。试图重新创建一个像 www.testandtrack.io 这样的网站
On running the command:
在运行命令时:
python manage.py inspectdb
I get the error:
我收到错误:
mysqlclient 1.3.13 or newer is required; you have 0.9.3
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!)
我已经尝试了所有建议的修复,包括: -upgrading pip -installing a different wheel(32 位而不是 64),即 mysqlclient-1.4.2-cp37-cp37m-win32.whl 使用命令 pip install mysqlclient-1.4.2- cp37-cp37m-win32.whl(这可以正常工作,没有错误,但不能完成所需的工作!)
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.
我的目标是简单地将旧版 mysql 数据库(在 XAMPP 和 myphpadmin 中运行)连接到 Django。我遵循了文档,但它忽略了安装 mysqlclient 的需要,并且在这一点上卡住了。
回答by Diego Magalh?es
This is how I fixed it.
这就是我修复它的方式。
Go to your django/db/backends/mysql installation dir. Check your path in the error message.
转到您的 django/db/backends/mysql 安装目录。检查错误消息中的路径。
I'm using pipenv so my path is:
我正在使用 pipenv 所以我的路径是:
/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
Open file base.py and search for:
打开文件 base.py 并搜索:
version = Database.version_info
Put a passinside if and comment line:
在 if 和注释行中放置一个pass:
raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.version)
raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database. version)
Like this.
像这样。
if version < (1, 3, 13):
pass
'''
raise ImproperlyConfigured(
'mysqlclient 1.3.13 or newer is required; you have %s.'
% Database.__version__
)
'''
Save, close this file and open operations.py.
保存,关闭此文件并打开operations.py。
Search for:
搜索:
query = query.decode(errors='replace')
and change decode to encode
并将解码更改为编码
query = query.encode(errors='replace')
Now, try to run the server.
现在,尝试运行服务器。
@edit
@编辑
Until the time of this answer, I found no other way to solve it. Today there are better ways to deal with this problem. This answerhas a better approach.
直到这个答案的时候,我发现没有其他方法可以解决它。今天有更好的方法来处理这个问题。这个答案有一个更好的方法。
回答by WisZhou
I guess your project uses pymysql instead of mysqlclient.
我猜你的项目使用 pymysql 而不是 mysqlclient。
You can try to search the following code snippet in your project. If you find it, please try the following methods to fix this problem:
您可以尝试在您的项目中搜索以下代码片段。如果找到,请尝试以下方法解决此问题:
import pymysql
pymysql.install_as_MySQLdb()
Insert a line of code between these two to make it look like this:
在这两者之间插入一行代码,使其看起来像这样:
import pymysql
pymysql.version_info = (1, 3, 13, "final", 0)
pymysql.install_as_MySQLdb()
Then try to start your project.
然后尝试开始您的项目。
- Why do I know you are using pymysql? Because 0.9.3 is just the latest version of pymysql.
- Why use pymysql instead of mysqlclient for the project? Because it is easier to install. pymysql does not depend on system libraries, while mysqlclient relies on a series of system libraries such as libmysqlclient-dev.
- Why is mysqlclient difficult to install and Django still uses it by default? Because mysqlclient is faster and performs better. So if your project has high performance requirements, I suggest you remove the compatible code above and install mysqlclient in your project. If you need help during the installation of mysqlclient, please refer to this link: How to install Python MySQLdb module using pip?, and ensure
libssl-dev
has been installed beforepip install mysqlclient
.
- 为什么我知道你在使用 pymysql?因为 0.9.3 只是 pymysql 的最新版本。
- 为什么在项目中使用 pymysql 而不是 mysqlclient?因为它更容易安装。pymysql不依赖系统库,而mysqlclient依赖libmysqlclient-dev等一系列系统库。
- 为什么mysqlclient难安装,Django默认还在用?因为 mysqlclient 速度更快,性能更好。所以如果你的项目对性能要求比较高,建议你去掉上面的兼容代码,在你的项目中安装mysqlclient。如果您在安装 mysqlclient 过程中需要帮助,请参考此链接: 如何使用 pip 安装 Python MySQLdb 模块?,并确保
libssl-dev
之前已安装pip install mysqlclient
。
回答by Aftabul Islam
I have had the same issue as lower version of mysqlclient was installed due to pymysql.
由于pymysql安装了较低版本的 mysqlclient ,我遇到了同样的问题。
OS: Linux Mint 19.1
操作系统:Linux Mint 19.1
Python: 3.6.8
蟒蛇:3.6.8
Django: 2.2.2
姜戈:2.2.2
- Uninstall mysqlclient:
pip3 uninstall mysqlclient
- Uninstall pymysql:
pip3 uninstall pymysql
- Install mysqlclient:
pip3 install mysqlclient
- 卸载mysqlclient:
pip3 uninstall mysqlclient
- 卸载pymysql:
pip3 uninstall pymysql
- 安装mysql客户端:
pip3 install mysqlclient
回答by NM666
this problem occurs when you create Django project in pycharm by default settings. It's caused by the default version of django is 2.2.6, so just downgrade the django version to 2.1.7, and error in the terminal is gone.
默认情况下在pycharm中创建Django项目时会出现此问题。这是由于django的默认版本是2.2.6造成的,所以只需将django版本降级到2.1.7,终端错误就消失了。
pip install Django==2.1.7
that's all!
就这样!
回答by fsalazar_sch
Instead of edit internal configuration, try to upgrade the version of mysqlclient
与其编辑内部配置,不如尝试升级mysqlclient的版本
pip3 install -U mysqlclient
回答by Alex Shchegretsov
If it's not critical for you, as a variant, just downgrade your django framework
from 2.2.2
(for example) to 2.1
.
如果它对您来说并不重要,作为变体,只需将您django framework
的2.2.2
(例如)降级到2.1
.
回答by Ngoni Mugandani
I had a similar issue, I was getting
我有一个类似的问题,我得到
"django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 1.3.12."
“django.core.exceptions.ImproperlyConfigured: 需要 mysqlclient 1.3.13 或更新版本;你有 1.3.12。”
So I went to the C:\Users\username\Envs\env\Lib\site-packages\django\db\backends\mysql
, opened base.pyand changed that line...
所以我去了C:\Users\username\Envs\env\Lib\site-packages\django\db\backends\mysql
,打开base.py并更改了该行...
if version < (1, 3, 13):
to...
到...
if version < (1, 3, 10):
which is a version lesser than mine and it worked.
这是一个低于我的版本并且它有效。
回答by Dolidod Teethtard
Install wheel:
pip install wheel
Download file that you want from here: https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python
Move to your Downloads directory (I guess it'll be
cd Downloads
)- Install downloaded file with:
pip install <file name>
安装轮子:
pip安装轮
从这里下载你想要的文件:https: //www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python
移动到您的下载目录(我想它会是
cd Downloads
)- 安装下载的文件:
pip install <file name>
WARNING!! You CANT edit name of downloaded .whl file. It contains some information what is required to install.
警告!!您不能编辑下载的 .whl 文件的名称。它包含一些安装所需的信息。
回答by girishsaraf03
I was finding a solution for this issue from a long time. I was using Ubuntu 18.04 and found this solution to be useful for python version 3.7.5
很长一段时间以来,我一直在为这个问题寻找解决方案。我使用的是 Ubuntu 18.04,发现这个解决方案对 python 3.7.5 版很有用
Step 1. Install libpython3.7-dev via sudo apt-get install
步骤 1. 通过 sudo apt-get install 安装 libpython3.7-dev
> sudo apt-get install libpython3.7-dev
Step 2: Install mysqlclient
第二步:安装mysqlclient
> python3 -m pip install mysqlclient==1.4.6
回答by Luis Valverde
The following solution works in Django 3.2.3 to get rid of the 'mysqlclient 1.3.13 or newer is required; you have 0.9.3' problem:
以下解决方案适用于 Django 3.2.3 以摆脱 'mysqlclient 1.3.13 或更高版本是必需的;你有 0.9.3' 问题:
1) pip uninstall mysqlclient # remove old version
2) pip install mysqlclient==1.3.13
3) comment or remove the old workaround in __init__.py of the main app.
1) pip uninstall mysqlclient # remove old version
2) pip install mysqlclient==1.3.13
3) comment or remove the old workaround in __init__.py of the main app.
# workaround django.core.exceptions.ImproperlyConfigured:
#Error loading MySQLdb module.
#Did you install mysqlclient?
#import pymysql
#pymysql.install_as_MySQLdb()
# workaround django.core.exceptions.ImproperlyConfigured:
#Error loading MySQLdb module.
#Did you install mysqlclient?
#import pymysql
#pymysql.install_as_MySQLdb()