1

I am trying to install pip install mysqlclient and it fails everytime. I also tried pip install --only-binary :all: mysqlclient and also not worked. Then I also downloaded whl file and also did't work. I need help. Using python 3.7.2 and pip 19.0.2 version. Here's the whole error thats pop up:

Running setup.py clean for mysqlclient
Failed to build mysqlclient
Installing collected packages: mysqlclient
Running setup.py install for mysqlclient ... error
  Complete output from command c:\users\vertig~1.0\envs\mypro\scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\VERTIG~1.0\\AppData\\Local\\Temp\\pip-install-b81i8gmq\\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\VERTIG~1.0\AppData\Local\Temp\pip-record-6s1gmot9\install-record.txt --single-version-externally-managed --compile --install-headers c:\users\vertig~1.0\envs\mypro\include\site\python3.7\mysqlclient:
  running install
  running build
  running build_py
  creating build
  creating build\lib.win32-3.7
  creating build\lib.win32-3.7\MySQLdb
  copying MySQLdb\__init__.py -> build\lib.win32-3.7\MySQLdb
  copying MySQLdb\_exceptions.py -> build\lib.win32-3.7\MySQLdb
  copying MySQLdb\compat.py -> build\lib.win32-3.7\MySQLdb
  copying MySQLdb\connections.py -> build\lib.win32-3.7\MySQLdb
  copying MySQLdb\converters.py -> build\lib.win32-3.7\MySQLdb
  copying MySQLdb\cursors.py -> build\lib.win32-3.7\MySQLdb
  copying MySQLdb\release.py -> build\lib.win32-3.7\MySQLdb
  copying MySQLdb\times.py -> build\lib.win32-3.7\MySQLdb
  creating build\lib.win32-3.7\MySQLdb\constants
  copying MySQLdb\constants\__init__.py -> build\lib.win32-3.7\MySQLdb\constants
  copying MySQLdb\constants\CLIENT.py -> build\lib.win32-3.7\MySQLdb\constants
  copying MySQLdb\constants\CR.py -> build\lib.win32-3.7\MySQLdb\constants
  copying MySQLdb\constants\ER.py -> build\lib.win32-3.7\MySQLdb\constants
  copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win32-3.7\MySQLdb\constants
  copying MySQLdb\constants\FLAG.py -> build\lib.win32-3.7\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/

  ----------------------------------------
Command "c:\users\vertig~1.0\envs\mypro\scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\VERTIG~1.0\\AppData\\Local\\Temp\\pip-install-b81i8gmq\\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\VERTIG~1.0\AppData\Local\Temp\pip-record-6s1gmot9\install-record.txt --single-version-externally-managed --compile --install-headers c:\users\vertig~1.0\envs\mypro\include\site\python3.7\mysqlclient" failed with error code 1 in C:\Users\VERTIG~1.0\AppData\Local\Temp\pip-install-b81i8gmq\mysqlclient\```

So any ideas where the error is getting?

Vince D
  • 137
  • 3
  • 14
  • 1
    Since you are a new contributor, i'll suggest you to always post the error message with your question. Otherwise no one can actually help you. Better edit your question and add the error message you received. Also add pip and mysql version you are using. – im_bhatman Feb 16 '19 at 14:03
  • Install 64 bit Python 3.7.x if you can. There is an official wheel for 64 bit Python 3.7 on Windows. If you use 32 bit Python, you’ll have to install from source (which can be tricky) or [install an unofffical wheel](https://stackoverflow.com/a/51164104/113962). – Alasdair Feb 16 '19 at 14:30
  • 1
    @Alasdair I already installed 64 it python and also download 64-bit wheel file. And also tried this in cmd: `pip install mysqlclient-1.4.2-cp37-cp37m-win_amd64` and it shows this: `Could not find a version that satisfies the requirement mysqlclient-1.4.2-cp37-cp37m-win_amd64 (from versions: ) No matching distribution found for mysqlclient-1.4.2-cp37-cp37m-win_amd64` – Vince D Feb 16 '19 at 14:38
  • @hackSlanger can I ask how to check my mysql version in cmd – Vince D Feb 16 '19 at 14:39
  • If you want to install a downloaded wheel, then you need the full filename including `.whl`. – Alasdair Feb 16 '19 at 15:03
  • @Alasdair I also tried with .whl but didn't work that's why I used trying without extension – Vince D Feb 17 '19 at 11:32
  • *didn't work* isn't enough information. We can't help if you don't show the exact command and the error. – Alasdair Feb 17 '19 at 14:07
  • @VinceD you can run `pip freeze > requirements.txt` and then go and check the requirements.txt file with ==, where PACKAGE_NAME is the mysql-client or any other package you are using and VERSION is the package's used version. – im_bhatman Mar 10 '20 at 10:11

2 Answers2

3

Check that you have MySQL installed on your system.

On Mac:

brew install mysql

Installing with APT (eg, Ubuntu):

sudo apt install mysql-server

Or install with the installer: https://dev.mysql.com/downloads/installer/.

Justin Shenk
  • 538
  • 1
  • 4
  • 17
0

error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": https://visualstudio.microsoft.com/downloads/

From the error message its pretty clear that the issue is with with C++ installation on your machine.

FYI: Many Python libs uses C++ under the hood so its mandatory to install the Microsoft visual c++(on windows) as mentioned in the error. You can go ahead and install Microsoft Visual C++ from here or here

Or else if there is no particular use behind mysqlclient you can use this pure pyython MySQL client library named PyMySQL (you need not install visual c++ for using this lib).

im_bhatman
  • 896
  • 1
  • 18
  • 28