[PYTHON] mysqlclient installation error solution [Mac, Windows version]

Introduction

In this article, I will post a solution to a common (almost 100%) error when installing mysqlclient.

pip install mysqlclient  #Error occurred

I'm using MySQL for the database in my environment, and I'm using it for web scraping and Django. In particular, mysqlclient is a must if you want Django to treat MySQL as a database.

I have experience building environments on both Windwos and MacOS, and I have been suffering from this problem every time. There are various solutions, and there were many cases where I tried them but they didn't work, so I would like to share the best solution based on my experience.

Windows

From the conclusion, ** Download the wheel package and install the package **.

Please download the wheel package from the following site. https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient

Please note that you should download the version that suits your environment. In my environment, "Python 3.8.0 64-bit" is installed and used, so

mysqlclient‑1.4.6‑cp38‑cp38‑win_amd64.whl

Download.

If you are using "Visual Studio Code" as an editor, please check it as it is displayed at the bottom left of the screen.

Python 3.5 => cp35
Python 3.6 => cp36
Python 3.7 => cp37

32-bit =>win32
64-bit =>win_amd64

After downloading, enter the directory containing the file and execute the command.

Writer environment
pip install mysqlclient‑1.4.6‑cp38‑cp38‑win_amd64.whl

Did you install it? If you couldn't, please check the version again.

I'm sorry if you still couldn't do it. .. ..

For this solution, I referred to this site and was able to solve my environment as well.

By the way, the author

Install "Build Tools for Visual Studio 2017" and

error: Microsoft Visual C++ 14.0 is required.

Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools

I gave up on the part of "'mysql.h': No such file or directory".

_mysql.c(29): fatal error C1083: include

'mysql.h':No such file or directory

Mac

The following error occurred in my environment.

ld: library not found for -lssl

On a Mac, open a terminal and execute the commands in order.

(1) xcode-select --install

(2) brew install mysql-connector-c

(3) sudo vim /usr/local/bin/mysql_config

    /libs="-L$pkglibdir"`And press Enter.

Press I to confirm that you have changed to INSERT mode and change as follows.

  #Change before
  libs="-L$pkglibdir"
  libs="$libs -l "

  #After change
  libs="-L$pkglibdir"
  libs="$libs -lmysqlclient -lssl -lcrypto"

Press esc to exit INSERT mode, then:Press qs.

(4) brew info openssl

I'm sure it came out a lot, but pay attention to Caveats.
  If you need to ...Please execute the following command.

Commands in my environment
  `>> ~/.zshrc`The part is subject to change depending on the environment. (~/.bash_profile etc.)

  echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc

  echo 'export LDFLAGS="-L/usr/local/opt/[email protected]/lib"' >> ~/.zshrc

  echo 'export CPPFLAGS="-I/usr/local/opt/[email protected]/include"' >> ~/.zshrc

(5)Reboot the terminal and`pip install mysqlclient`To execute.

What do you think? Did you install it successfully?

For this solution, please refer to this site. I was able to solve it.

At the end

Did you successfully install mysqlclient? Please enjoy MySQL Life in the future!

References

Windows solution https://shimi-dai.com/python-install-mysqlclient-on-windows/

Mac solution https://stackoverflow.com/questions/51578425/mysqlclient-instal-error-raise-exceptionwrong-mysql-configuration-maybe-htt

Recommended Posts

mysqlclient installation error solution [Mac, Windows version]
[2021 version] Python installation Windows 10 (64bit) edition
Solution for pip install error [Python] [Mac]
Jupyter installation error
centOS 7 installation error
Python installation (Windows)
Django2.2 SQLite3 version error
Installation of OpenMDAO (version 1.7.1)
Python installation method Windows
numba installation on mac
Prepare Python development environment with Mac + Windows + VisualStudio Code (Windows version)
Prepare Python development environment with Mac + Windows + VisualStudio Code (Mac version)
mysqlclient / Mysql-python installation cc1: error: unrecognized command line option "-arch"