Trying to install mysqlclient using pip3 on Python 3.6.0
$ pip3 install mysqlclient
Collecting mysqlclient
Using cached mysqlclient-1.3.10.tar.gz
Comp
After extensive troubleshooting, I found that the brew install mysql-connector-c
just does not work.
The problem stems from the system not being able to identify that mysql_config
is installed (which is what mysql-connector-c
essentially does). Homebrew's method (open for argument) of installing the mysql-connector-c
in its /Cellar/
and creating a symlink to the /usr/local/bin/
directory seems to be causing problems as Python tries to follow the symlink.
To resolve the issue I performed the following:
brew uninstall mysql-connector-c
.dmg
, no need to be complicated here...which mysql_config
/usr/local/bin/mysql/bin/mysql_config
activate virtualenv
(if applicable)
pip install mysqlclient
There may be other ways to still use Homebrew, but this was the most straightforward solution I found.
Note that the mysqlclient
GitHub README.md also states that the C-developer headers for Python3 are needed. I assume that mysql-connector-c
includes those; however, should you run into more issues, you might also install the Xcode Developer CI Tools for good measure.
xcode-select --install
They include the C compiler and other developer utilities from Apple. Read more here.
This worked for me:
brew install mysql-connector-c
edit mysql_config
(locate it: which mysql_config
)
correct this in mysql_config:
# Create options
libs="-L$pkglibdir"
libs="$libs -l "
It shoud be:
# Create options
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"
brew info openssl
pip3 install mysqlclient
For Python 2.7 on specific programs:
This solved all issues I was having running a program that ran on Python 2.7 on and older version of MySql
I'm just getting started with python and had similar problems when trying to do pip3 install mysqlclient
to connect Django to MySQL 8.0.19 but on my case it is on a macOS Catalina 10.15.5 with Python 3.8. I also tried brew install mysql-connector-c
but it also gave me a lot of trouble. Here's how I manage to make it work.
brew reinstall mysql
brew install mysql-client
mysql-client
I got the following messages in the terminal which I just followed and got all to work.echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.zshrc
export LDFLAGS="-L/usr/local/opt/mysql-client/lib"
export CPPFLAGS="-I/usr/local/opt/mysql-client/include"
pip3 install mysqlclient
References: Install mysqlclient for Django Python on Mac OS X Sierra
Hope this works as it did for me today. Regards, Alfredo
I resolved this installing libmysqlclient-dev first:
sudo apt-get install libmysqlclient-dev
Hope it works for you.
Personally I recommend using pymysql
instead of using mysqlclient
. You can install pymysql
with:
pip install pymysql
And you might edit your SQLAlchemy URL to:
mysql+pymysql://username:passwd@hostname/database