In my virtual environment, i installed flask ( pip install flask
) and then Flask-MySQLdb ( pip install Flask-MySQLdb
)
(venv) E:\Flask>pip install Flask-MySQLdb
I checked that Flask is properly installed:
(venv) E:\Flask>flask --version
Python 3.8.3
Flask 1.1.2
Werkzeug 1.0.1
But while installing Flask-MySQLdb
I'm getting following error:
Collecting Flask-MySQLdb
Using cached https://files.pythonhosted.org/packages/62/e3/955c845efe1aacf30c8e2607470544ede36aa1044f6382c809f13e014104/Flask-MySQLdb-0.2.0.tar.gz
Requirement already satisfied: Flask>=0.10 in e:\flask\venv\lib\site-packages (from Flask-MySQLdb) (1.1.2)
Collecting mysqlclient (from Flask-MySQLdb)
Using cached https://files.pythonhosted.org/packages/a5/e1/e5f2b231c05dc51d9d87fa5066f90d1405345c54b14b0b11a1c859020f21/mysqlclient-2.0.1.tar.gz
Requirement already satisfied: itsdangerous>=0.24 in e:\flask\venv\lib\site-packages (from Flask>=0.10->Flask-MySQLdb) (1.1.0)
Requirement already satisfied: Jinja2>=2.10.1 in e:\flask\venv\lib\site-packages (from Flask>=0.10->Flask-MySQLdb) (2.11.2)
Requirement already satisfied: click>=5.1 in e:\flask\venv\lib\site-packages (from Flask>=0.10->Flask-MySQLdb) (7.1.2)
Requirement already satisfied: Werkzeug>=0.15 in e:\flask\venv\lib\site-packages (from Flask>=0.10->Flask-MySQLdb) (1.0.1)
Requirement already satisfied: MarkupSafe>=0.23 in e:\flask\venv\lib\site-packages (from Jinja2>=2.10.1->Flask>=0.10->Flask-MySQLdb) (1.1.1)
Installing collected packages: mysqlclient, Flask-MySQLdb
Running setup.py install for mysqlclient ... error
ERROR: Command errored out with exit status 1:
command: 'e:\flask\venv\scripts\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Nitish\\AppData\\Local\\Temp\\pip-install-l__3nshn\\mysqlclient\\setup.py'"'"'; __file__='"'"'C:\\Users\\Nitish\\AppData\\Local\\Temp\\pip-install-l__3nshn\\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\Nitish\AppData\Local\Temp\pip-record-6biidbgp\install-record.txt' --single-version-externally-managed --compile --install-headers 'e:\flask\venv\include\site\python3.8\mysqlclient'
cwd: C:\Users\Nitish\AppData\Local\Temp\pip-install-l__3nshn\mysqlclient\
Complete output (23 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\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
error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": https://visualstudio.microsoft.com/downloads/
----------------------------------------
ERROR: Command errored out with exit status 1: 'e:\flask\venv\scripts\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Nitish\\AppData\\Local\\Temp\\pip-install-l__3nshn\\mysqlclient\\setup.py'"'"'; __file__='"'"'C:\\Users\\Nitish\\AppData\\Local\\Temp\\pip-install-l__3nshn\\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\Nitish\AppData\Local\Temp\pip-record-6biidbgp\install-record.txt' --single-version-externally-managed --compile --install-headers 'e:\flask\venv\include\site\python3.8\mysqlclient' Check the logs for full command output.
My python version: 3.8.3
My pip version: 19.2.3
Update: I installed Microsoft Visual C++ tools. Now I'm getting these errors:
Running setup.py install for mysqlclient ... error
ERROR: Command errored out with exit status 1:
command: 'e:\flask\venv\scripts\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Nitish\\AppData\\Local\\Temp\\pip-install-kwo28o72\\mysqlclient\\setup.py'"'"'; __file__='"'"'C:\\Users\\Nitish\\AppData\\Local\\Temp\\pip-install-kwo28o72\\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\Nitish\AppData\Local\Temp\pip-record-_plr9xlx\install-record.txt' --single-version-externally-managed --compile --install-headers 'e:\flask\venv\include\site\python3.8\mysqlclient'
cwd: C:\Users\Nitish\AppData\Local\Temp\pip-install-kwo28o72\mysqlclient\
Complete output (29 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\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 14.0\VC\BIN\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Dversion_info=(2,0,1,'final',0) -D__version__=2.0.1 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include\mariadb" -Ie:\flask\venv\include -IC:\Python\Python383\include -IC:\Python\Python383\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\winrt" /TcMySQLdb/_mysql.c /Fobuild\temp.win32-3.8\Release\MySQLdb/_mysql.obj /Zl /D_CRT_SECURE_NO_WARNINGS
_mysql.c
MySQLdb/_mysql.c(29): fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\cl.exe' failed with exit status 2
----------------------------------------
ERROR: Command errored out with exit status 1: 'e:\flask\venv\scripts\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Nitish\\AppData\\Local\\Temp\\pip-install-kwo28o72\\mysqlclient\\setup.py'"'"'; __file__='"'"'C:\\Users\\Nitish\\AppData\\Local\\Temp\\pip-install-kwo28o72\\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\Nitish\AppData\Local\Temp\pip-record-_plr9xlx\install-record.txt' --single-version-externally-managed --compile --install-headers 'e:\flask\venv\include\site\python3.8\mysqlclient' Check the logs for full command output.
RESOLVED
- initially the error was related to Microsoft Visual Build Tools:
error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": https://visualstudio.microsoft.com/downloads/
So I installed Visual Build Tools
- then I got error:
MySQLdb/_mysql.c(29): fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\cl.exe' failed with exit status 2
It happens to be that the error was due to 32 bit version python installed on 64 bit system as pointed out here(https://stackoverflow.com/a/53790200/13504510). The error was resolved by following the steps from this answer:
https://stackoverflow.com/a/51294860/13504510
for my case it got solved by installing this:
mysqlclient-1.4.6-cp38-cp38-win32.whl
from https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient
Try out which works for you. If the whl file is not supported on your system, then it should look like this:
pip install mysqlclient-1.4.6-cp39-cp39-win_amd64.whl
ERROR: mysqlclient-1.4.6-cp39-cp39-win_amd64.whl is not a supported wheel on this platform.
otherwise it will get installed successfully!
After that again try pip install Flask-MySQLdb
and it should do the job!