程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

django. core. exceptions. ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3

編輯:Python
stay ubuntu To establish django Project time , There was a mistake , After consulting relevant materials and documents , Summed up the solution to this error , Whether in the linux in , Still windows or mac In the system , The solution steps are similar , It's just that the location of the file is different

First step :

Download and install PyMySQL, And in the project file with the same name as the project __init__.py Add the following code to . If your image source has not been changed , You can refer to Python Switch pip Mirror source , After change , Download speed will be much faster

# install pymysql
pip install pymysql
# __init__.py
import pymysql
pymysql.install_as_MySQLdb()

The second step :

  • Method 1 :
    Just lower django The version of .

    # Access terminal , Sometimes according to pip On the version , Need to use pip3
    # Input pip uninstall django, Remove django2.2
    C:\Users\Administrator>pip uninstall django
    # Input pip install django==2.1.4, Install version of django
    C:\Users\Administrator>pip install django==2.1.4
    

    If you can't uninstall , Direct installation is also possible

  • Method 2 :
    Continue to use the current version (django=2.2)

    # find python In the environment django package , And then into db Under the backends Under the mysql Folder 
    cd /home/wls/.local/lib/python3.6/site-packages/django/db/backends/mysql
    

    Don't know django What about the installation directory of ? Continue to read down , Methods are presented immediately

    # ubuntu System or windows Under the system 
    # Access terminal , Then enter python, Enter the following command 
    [email protected]:~$ python3
    Python 3.6.8 (default, Jan 14 2019, 11:02:34)
    [GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import django
    >>> print(django.__path__)
    ['/home/wls/.local/lib/python3.6/site-packages/django']
    # windows Enter the terminal under the system 
    C:\Users\Administrator>pip show django
    ......
    Location: f:\python\lib\site-packages
    

    Both of the above methods can be found django Installation path for , Is it exciting

The third step :

On the basis of step 2, method 2 , find base.py file , And use vi or vim open base.py file , Comment the relevant code , As shown in the figure below :

# notes base.py The following part of the code in the file 
if version < (1, 3, 13):
raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)

It's finally over , Be accomplished , Then there will be errors when running the project , At this time, a cool song should be played , More suitable for the current atmosphere

 Error message :
AttributeError: 'str' object has no attribute 'decode'

It is also found in the directory in the previous step operations.py Document and use vi or vim open operations.py file , Comment the relevant code :

# notes operations.py The following part of the code in the file ( This file is a bit long , Take your time ), take decode It is amended as follows encode
# ubuntu in vim Find with shortcut keys : ?decode
if query is not None:
query = query.decode(errors='replace')
return query
# It is amended as follows 
if query is not None:
query = query.encode(errors='replace')
return query

And that's it

Articles you may be interested in

  • python in print Print display color
  • Python It's a deep and shallow copy
  • You don't know Python in global、nonlocal What's up

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved