0

i am new in Django.i want to use Mysql database for my project.i am installing mysqlclient for that, but its showing below error. i am using --pip install mysql-python command for installing mysqlclient

Collecting mysql-python   Using cached MySQL-python-1.2.5.zip (108 kB) Using legacy setup.py install for mysql-python, since package 'wheel' is not installed. Installing collected packages: mysql-python
    Running setup.py install for mysql-python ... error
    ERROR: Command errored out with exit status 1:
     command: 'f:\xampp\htdocs\django\scripts\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\DELL\\AppData\\Local\\Temp\\pip-install-ti26jpbi\\mysql-python\\setup.py'"'"';
__file__='"'"'C:\\Users\\DELL\\AppData\\Local\\Temp\\pip-install-ti26jpbi\\mysql-python\\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\DELL\AppData\Local\Temp\pip-record-h90u4076\install-record.txt'
--single-version-externally-managed --compile --install-headers 'f:\xampp\htdocs\django\include\site\python3.8\mysql-python'
         cwd: C:\Users\DELL\AppData\Local\Temp\pip-install-ti26jpbi\mysql-python\
    Complete output (24 lines):
    running install
    running build
    running build_py
    creating build
    creating build\lib.win32-3.8
    copying _mysql_exceptions.py -> build\lib.win32-3.8
    creating build\lib.win32-3.8\MySQLdb
    copying MySQLdb\__init__.py -> build\lib.win32-3.8\MySQLdb
    copying MySQLdb\converters.py -> build\lib.win32-3.8\MySQLdb
    copying MySQLdb\connections.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\CR.py -> build\lib.win32-3.8\MySQLdb\constants
    copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win32-3.8\MySQLdb\constants
    copying MySQLdb\constants\ER.py -> build\lib.win32-3.8\MySQLdb\constants
    copying MySQLdb\constants\FLAG.py -> build\lib.win32-3.8\MySQLdb\constants
    copying MySQLdb\constants\REFRESH.py -> build\lib.win32-3.8\MySQLdb\constants
    copying MySQLdb\constants\CLIENT.py -> build\lib.win32-3.8\MySQLdb\constants
    running build_ext
    building '_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: 'f:\xampp\htdocs\django\scripts\python.exe' -u
-c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\DELL\\AppData\\Local\\Temp\\pip-install-ti26jpbi\\mysql-python\\setup.py'"'"';
__file__='"'"'C:\\Users\\DELL\\AppData\\Local\\Temp\\pip-install-ti26jpbi\\mysql-python\\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\DELL\AppData\Local\Temp\pip-record-h90u4076\install-record.txt'
--single-version-externally-managed --compile --install-headers 'f:\xampp\htdocs\django\include\site\python3.8\mysql-python' Check the logs for full command output.

i an using windows 10. i appreciate if anyone can help me with this error.

4
  • use my answer here stackoverflow.com/a/61293962/5193536 Commented Jul 27, 2020 at 10:28
  • MySQL-python only supports Python 2. Use pip install mysqlclient to install mysqlclient. Make sure you have 64-bit Python installed - that way it will install the wheel. Commented Jul 27, 2020 at 10:28
  • i am getting same error with pip install mysqlclient . Commented Jul 27, 2020 at 10:33
  • It might be a similar error for mysqlclient but it won't be the same, so please show that error instead. As I said before the easiest solution is to switch to 64-bit Python then you won't have to build mysqlclient. Commented Jul 27, 2020 at 10:48

4 Answers 4

2

I will point out 2 solutions. Choose based on your needs.

  1. Easy solution. Please note that this is an alternative, not a fix. Also this will not get you the latest version. As long as it suits your needs might be good enough.
  1. Better solution. This is a fix for pip install mysqlclient. Please follow step by step although it's dummy, but it works:
  • Go to: https://downloads.mysql.com/archives/c-c/
  • Download and install the x64 version;
  • Move C:\Program Files\MySQL\MySQL Connector C 6.1 to C:\Program Files (x86)\MySQL\MySQL Connector C 6.1;
  • Go to: https://mariadb.com/downloads/connectors/connectors-data-access/c-connector
  • Download and install latest C connector available for MS Windows (x64 bit)
  • Go to C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include
  • Create a directory(folder) named: mariadb
  • Copy contents from C:\Program Files\MariaDB\MariaDB Connector C 64-bit\include to C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include\mariadb
  • Go to C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\lib
  • Create a directory(folder) named: mariadb
  • Copy contents from C:\Program Files\MariaDB\MariaDB Connector C 64-bit\lib to C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\lib\mariadb
  • Run pip install mysqlclient
  • Done!

Test: Tested both above solutions using latest available configurations:

  • python 3.10
  • mysql 8.0.27
  • django 3.2.9

FYI: Those are not the only 2 solutions. For instance if you dockerize, use a VM or simply use the new capability of windows 10 to have ubuntu as an app you can fix this as well.

Sign up to request clarification or add additional context in comments.

Comments

0

You either need to install Microsoft Visual C++ 14.0 tools containing the C++ compiler: https://wiki.python.org/moin/WindowsCompilers

OR

You can download pre-compiled binaries for many libraries here: https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient (usual warnings about package sourcing applies)

1 Comment

Currently, there are official wheels for the latest mysqlclient release for 64-bit Python on Windows.
0

You can simply download the mysqlclient from here. just check the verion of your python and download the .whl file.

Then just copy the file name in command prompt go to the downloads folder and type

pip install {fullfile name}

Comments

0

Please have a look carefully at this line in the error message you provided:

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

There is an answer to what are you looking for.

Comments