Trying to install mysqlclient using pip3 on Python 3.6.0
$ pip3 install mysqlclient
Collecting mysqlclient
Using cached mysqlclient-1.3.10.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/3k/08g3yx_12kg99kyfs989md600000gn/T/pip-build-1qv_89jc/mysqlclient/setup.py", line 17, in <module>
metadata, options = get_config()
File "/private/var/folders/3k/08g3yx_12kg99kyfs989md600000gn/T/pip-build-1qv_89jc/mysqlclient/setup_posix.py", line 54, in get_config
libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
File "/private/var/folders/3k/08g3yx_12kg99kyfs989md600000gn/T/pip-build-1qv_89jc/mysqlclient/setup_posix.py", line 54, in <listcomp>
libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
File "/private/var/folders/3k/08g3yx_12kg99kyfs989md600000gn/T/pip-build-1qv_89jc/mysqlclient/setup_posix.py", line 12, in dequote
if s[0] in "\"'" and s[0] == s[-1]:
IndexError: string index out of range
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/3k/08g3yx_12kg99kyfs989md600000gn/T/pip-build-1qv_89jc/mysqlclient/
Already did
brew install mysql-connector-c
But still getting this error
The command python setup.py egg_info failed with error code 1 can also be caused by the pip itself. If you are using an old version of pip, we recommend you update it to the latest version. To do so, you just need to run python -m pip install -U pip in the elevated Command Prompt.
You may need to install the Python 3 and MySQL development headers and libraries like so: Then you can install mysqlclient via pip now: mysqlclient uses mysql_config or mariadb_config by default for finding compiler/linker flags. You can use MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS environment variables to customize compiler/linker options.
Then you can install mysqlclient via pip now: mysqlclient uses mysql_config or mariadb_config by default for finding compiler/linker flags. You can use MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS environment variables to customize compiler/linker options. Download the file for your platform.
To do so, you just need to run python -m pip install -U pip in the elevated Command Prompt. Tip: If this command can’t fix the pip error code 1, you can try running the python3 -m pip3 install -U pip command.
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
I resolved this installing libmysqlclient-dev first:
sudo apt-get install libmysqlclient-dev
Hope it works for you.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With