[Django] How to resolve errors when installing mysqlclient

environment

Windows 10 Home Python 3.8.1 Django 3.0.7

error contents

When I install mysqlclient, which is recommended for Django 2.2 and later, I get the following lengthy error:

(venv) C:\Development\django-project\django_project>pip install mysqlclient

python


Collecting mysqlclient
  Using cached mysqlclient-1.4.6.tar.gz (85 kB)
Using legacy setup.py install for mysqlclient, since package 'wheel' is not installed.
Installing collected packages: mysqlclient
    Running setup.py install for mysqlclient ... error
    ERROR: Command errored out with exit status 1:
     command: 'c:\development\django-project\venv\scripts\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Ryozo\\AppData\\Local\\Temp\\pip-install-qnbecfcr\\mysqlclient\\setup.py
'"'"'; __file__='"'"'C:\\Users\\Ryozo\\AppData\\Local\\Temp\\pip-install-qnbecfcr\\mysqlclient\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"')
;f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\Ryozo\AppData\Local\Temp\pip-record-isgb1l1w\install-record.txt' --single-version-externally-managed --compile --install-headers
 'c:\development\django-project\venv\include\site\python3.8\mysqlclient'
         cwd: C:\Users\Ryozo\AppData\Local\Temp\pip-install-qnbecfcr\mysqlclient\
    Complete output (30 lines):
    running install
    running build
    running build_py
    creating build
    creating build\lib.win32-3.8
    creating build\lib.win32-3.8\MySQLdb
    copying MySQLdb\__init__.py -> build\lib.win32-3.8\MySQLdb
    copying MySQLdb\_exceptions.py -> build\lib.win32-3.8\MySQLdb
    copying MySQLdb\compat.py -> build\lib.win32-3.8\MySQLdb
    copying MySQLdb\connections.py -> build\lib.win32-3.8\MySQLdb
    copying MySQLdb\converters.py -> build\lib.win32-3.8\MySQLdb
    copying MySQLdb\cursors.py -> build\lib.win32-3.8\MySQLdb
    copying MySQLdb\release.py -> build\lib.win32-3.8\MySQLdb
    copying MySQLdb\times.py -> build\lib.win32-3.8\MySQLdb
    creating build\lib.win32-3.8\MySQLdb\constants
    copying MySQLdb\constants\__init__.py -> build\lib.win32-3.8\MySQLdb\constants
    copying MySQLdb\constants\CLIENT.py -> build\lib.win32-3.8\MySQLdb\constants
    copying MySQLdb\constants\CR.py -> build\lib.win32-3.8\MySQLdb\constants
    copying MySQLdb\constants\ER.py -> build\lib.win32-3.8\MySQLdb\constants
    copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win32-3.8\MySQLdb\constants
    copying MySQLdb\constants\FLAG.py -> build\lib.win32-3.8\MySQLdb\constants
    running build_ext
    building 'MySQLdb._mysql' extension
    creating build\temp.win32-3.8
    creating build\temp.win32-3.8\Release
    creating build\temp.win32-3.8\Release\MySQLdb
    C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Dversion_info=(1,4,6,'final',0) -D__version__=1.4.6 "-IC:\Pro
gram Files (x86)\MySQL\MySQL Connector C 6.1\include\mariadb" -Ic:\development\django-project\venv\include -IC:\Users\Ryozo\AppData\Local\Programs\Python\Python38-32\include -IC:\Users\Ryozo\AppData\Local\Programs
\Python\Python38-32\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\include" /TcMySQLdb/_mysql.c /Fobuild\temp.win32-3.8\Release\MySQLdb/_mysql.obj /Zl /D_CRT_SEC
URE_NO_WARNINGS
    _mysql.c
    MySQLdb/_mysql.c(29): fatal error C1083:Unable to open include file.'mysql.h':No such file or directory
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.26.28801\\bin\\HostX86\\x86\\cl.exe' failed with exit status 2
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\development\django-project\venv\scripts\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Ryozo\\AppData\\Local\\Temp\\pip-instal
l-qnbecfcr\\mysqlclient\\setup.py'"'"'; __file__='"'"'C:\\Users\\Ryozo\\AppData\\Local\\Temp\\pip-install-qnbecfcr\\mysqlclient\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().repl
ace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\Ryozo\AppData\Local\Temp\pip-record-isgb1l1w\install-record.txt' --single-version-externally-ma
naged --compile --install-headers 'c:\development\django-project\venv\include\site\python3.8\mysqlclient' Check the logs for full command output.

Solution

[Download] & install the whl file that suits your environment (https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient)

In my case it was mysqlclient- 1.4.6-cp38-cp38-win32.whl.

Move to the downloaded directory and execute the following command

python


(venv) C:\Development\django-project>pip install mysqlclient-1.4.6-cp38-cp38-win32.whl
Processing c:\development\django-project\mysqlclient-1.4.6-cp38-cp38-win32.whl
Installing collected packages: mysqlclient
Successfully installed mysqlclient-1.4.6

(venv) C:\Development\django-project>pip install mysqlclient
Requirement already satisfied: mysqlclient in c:\development\django-project\venv\lib\site-packages (1.4.6)

Now that the installation is complete, install it with pip install mysqlclient and it will say it's already there.

Recommended Posts

[Django] How to resolve errors when installing mysqlclient
How to resolve CSRF Protection when using AngularJS with Django
How to deal with errors when installing whitenoise and deploying to Heroku
How to deal with errors when installing Python and pip with choco
How to deal with errors when hitting pip ②
How to resolve SSL module errors in Anaconda environment
How to update user information when logging in to Django RemoteUserMiddleware
[Django] How to test Form [TDD]
Errors related to memcached in django
[Django memo] Failure when installing modal
How to add sudo when debugging
How to reflect CSS in Django
How to deal with DistributionNotFound errors
How to get started with Django
How to write Django1.9 environment-independent wsgi.py
How to authenticate with Django Part 2
How to authenticate with Django Part 3
[Tips] How to do template extends when creating HTML with django
How to do arithmetic with Django template
attempted relative import beyond top-level package and how to resolve when angry
How to check the version of Django
How to get IP when Tornado + nginx
How to delete expired sessions in Django
Solution for errors when deploying to Heroku
How to deal with enum compatibility errors
How to do Server-Sent Events in Django
[Python] How to deal with module errors
How to convert DateTimeField format in Django
How to add pre-save processing when adding objects on the Django admin site
How to avoid import errors when running python in Synology DSM Task Scheduler
How to start Python (Flask) when EC2 starts
How to implement Rails helper-like functionality in Django
How to set Django DB to mongodb visual studio 2019
How to develop a cart app with Django
How to reflect ImageField in Django + Docker (pillow)
How to run some script regularly in Django
[Django] How to get data by specifying SQL.
How to deal with run-time errors in subprocess.call
How to deal with SessionNotCreatedException when using Selenium
How to print debug messages to the Django console
How to fix when Terminal input becomes abnormal
How to implement "named_scope" of RubyOnRails with Django
How to remember when you forget a word
How to create a Rest Api in Django
When I try to install mysqlclient with Django, I get error: command'gcc' failed with exit status 1.
[Python] [Django] How to use ChoiceField and how to add options
How to get multiple model objects randomly in Django
[Ansible] How to use SSH password authentication when executing ansible
Memo of how to use properly when combining pandas.DataFrame
Steps from installing Django to displaying an html page
How to deploy a Django application on Alibaba Cloud
How to disable the reference feature when outputting PyYaml
How to use Azure Table storage from Django (PTVS)
How to access with cache when reading_json in pandas
How to build a Django (python) environment on docker
How to use bootstrap in Django generic class view
When you want to filter with Django REST framework
Steps from installing Python 3 to creating a Django app
How to exit when using Python in Terminal (Mac)
How to upload files in Django generic class view
How to use Django on Google App Engine / Python