5

I just purchased a new Macbook Pro with the M1 chip after ensuring that homebrew would work natively on it. I'm able to pip install any other library except mysqlclient, and I have no issue installing it via homebrew, so I'm wondering from the error message below, is this an issue with the mysqlclient not being updated for the latest version of Big Sur, or is this an issue with the new Macs itself? Just knowing that would be a great start for me, and if you had a suggestion on how to fix it, that'd be even better! Thank you!

ERROR: Command errored out with exit status 1:
     command: /Users/danieljonathanschaefer/Desktop/work/401GOVE/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/ht/p0kw7_d11ns61kqmpmfcy6b40000gn/T/pip-install-bifqtsix/mysqlclient_6f9d0caea513420ea2052d60956aab6d/setup.py'"'"'; __file__='"'"'/private/var/folders/ht/p0kw7_d11ns61kqmpmfcy6b40000gn/T/pip-install-bifqtsix/mysqlclient_6f9d0caea513420ea2052d60956aab6d/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/ht/p0kw7_d11ns61kqmpmfcy6b40000gn/T/pip-record-ukcglom_/install-record.txt --single-version-externally-managed --compile --install-headers /Users/danieljonathanschaefer/Desktop/work/401GOVE/include/site/python3.9/mysqlclient
         cwd: /private/var/folders/ht/p0kw7_d11ns61kqmpmfcy6b40000gn/T/pip-install-bifqtsix/mysqlclient_6f9d0caea513420ea2052d60956aab6d/
    Complete output (43 lines):
    mysql_config --version
    ['8.0.25']
    mysql_config --libs
    ['-L/opt/homebrew/Cellar/mysql/8.0.25_1/lib', '-lmysqlclient', '-lz', '-lzstd', '-lssl', '-lcrypto', '-lresolv']
    mysql_config --cflags
    ['-I/opt/homebrew/Cellar/mysql/8.0.25_1/include/mysql']
    ext_options:
      library_dirs: ['/opt/homebrew/Cellar/mysql/8.0.25_1/lib']
      libraries: ['mysqlclient', 'zstd', 'resolv']
      extra_compile_args: ['-std=c99']
      extra_link_args: []
      include_dirs: ['/opt/homebrew/Cellar/mysql/8.0.25_1/include/mysql']
      extra_objects: []
      define_macros: [('version_info', "(2,0,3,'final',0)"), ('__version__', '2.0.3')]
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.9-x86_64-3.9
    creating build/lib.macosx-10.9-x86_64-3.9/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb
    copying MySQLdb/_exceptions.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb
    copying MySQLdb/connections.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb
    copying MySQLdb/converters.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb
    copying MySQLdb/release.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb
    copying MySQLdb/times.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb
    creating build/lib.macosx-10.9-x86_64-3.9/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb/constants
    running build_ext
    building 'MySQLdb._mysql' extension
    creating build/temp.macosx-10.9-x86_64-3.9
    creating build/temp.macosx-10.9-x86_64-3.9/MySQLdb
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -I/opt/homebrew/opt/openssl@1.1/include -Dversion_info=(2,0,3,'final',0) -D__version__=2.0.3 -I/opt/homebrew/Cellar/mysql/8.0.25_1/include/mysql -I/Users/danieljonathanschaefer/Desktop/work/401GOVE/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c MySQLdb/_mysql.c -o build/temp.macosx-10.9-x86_64-3.9/MySQLdb/_mysql.o -std=c99
    gcc -bundle -undefined dynamic_lookup -arch x86_64 -g -L/opt/homebrew/opt/openssl@1.1/lib -I/opt/homebrew/opt/openssl@1.1/include build/temp.macosx-10.9-x86_64-3.9/MySQLdb/_mysql.o -L/opt/homebrew/Cellar/mysql/8.0.25_1/lib -lmysqlclient -lzstd -lresolv -o build/lib.macosx-10.9-x86_64-3.9/MySQLdb/_mysql.cpython-39-darwin.so
    ld: library not found for -lzstd
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    error: command '/usr/bin/gcc' failed with exit code 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /Users/danieljonathanschaefer/Desktop/work/401GOVE/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/ht/p0kw7_d11ns61kqmpmfcy6b40000gn/T/pip-install-bifqtsix/mysqlclient_6f9d0caea513420ea2052d60956aab6d/setup.py'"'"'; __file__='"'"'/private/var/folders/ht/p0kw7_d11ns61kqmpmfcy6b40000gn/T/pip-install-bifqtsix/mysqlclient_6f9d0caea513420ea2052d60956aab6d/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/ht/p0kw7_d11ns61kqmpmfcy6b40000gn/T/pip-record-ukcglom_/install-record.txt --single-version-externally-managed --compile --install-headers /Users/danieljonathanschaefer/Desktop/work/401GOVE/include/site/python3.9/mysqlclient Check the logs for full command output.
Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
Daniel Schaefer
  • 61
  • 1
  • 1
  • 2
  • 1
    It's complaining about libzstd, which is a zlib compression library. Try "brew install zstd" and see if things improve. – Tim Roberts Jun 07 '21 at 20:34
  • @TimRoberts I had it installed, the issue was that it's connecting to the python file on my virtual environment, not the one on my host machine where the zstd is located. I've never had this issue in the past, but maybe either the new chip or a new update changed something related to that. – Daniel Schaefer Jun 07 '21 at 21:24

7 Answers7

3

I got the same issue and I found this command,

brew install mysql-client

source: https://doesitarm.com/formula/mysql-client/

3

I got same problem in Mac Pro with M1 chip, then I used brew install zstd to install zstd then install mysqlclinent CFLAGS="-I$(brew --prefix)/include" LDFLAGS="-L$(brew --prefix)/lib" pip install mysqlclient

source : https://github.com/PyMySQL/mysqlclient/issues/497

3

On my mbp with m2pro, I solved it with the following command

brew install mysql-client pkg-config

export PKG_CONFIG_PATH="/opt/homebrew/opt/mysql-client/lib/pkgconfig"

pip install mysqlclient

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 27 '23 at 00:45
  • This helped me immediately while nothing else would. – VPZ Aug 13 '23 at 06:09
2

Yes, I had the same problem when I tried to do pip install mysqlclient on my MacBook Pro 2021 running Monterey 12.0.1 with an Apple Silicon M1 chip.

I used a solution by Github user jcbloch found in the discussion in the link https://github.com/PyMySQL/mysqlclient/issues/496 which I found after reading the https://github.com/PyMySQL/mysqlclient/issues/497 link that I found in sathira lamal's answer.

The problem, as I learned from reading jcbloch's explanation, is with the Python that currently comes with the MacBook Pro 2021 with Monterey 12.0.1. That Python is built for x86_64 architecture. The mysqlclient library however has an arm64 version available, which is what you are going to get by default if you do something like brew install mysql-client.

Using the file command shows the issue:

$ file /Library/Frameworks/Python.framework/Versions/2.7/bin/python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python: Mach-O 64-bit executable x86_64

The text above shows that python is x86_64.

$ file /opt/homebrew/opt/mysql-client/lib/libmysqlclient.21.dylib 
/opt/homebrew/opt/mysql-client/lib/libmysqlclient.21.dylib: Mach-O 64-bit dynamically linked shared library arm64

The text above shows that libmysqlclient.21.dylib is arm64.

To work around this, Github user jcbloch created an alternative Homebrew installation that is set to use x86_64 architecture, used it to install an x86_64 version of the MySQL client library, then used that library when installing the MySQL client into Python via pip.

Here is what I had to do, which is basically the same thing jcbloch suggests.

What differs is that I made sure to include an uninstall of any borked mysqlclient python package and to drop all the cached pip libraries so that you don't just end up reinstalling the cached incorrect package again. And, I ended up with a slightly later version of MySQL client than jcbloch did. And, I had to include an LDFLAGS variable to point to the x86_64 openssl library.

Make sure to double check all the paths below before executing these commands. I got derailed for many hours because I had copied and pasted the wrong version of the mysql library in my last command.

cd /opt
mkdir homebrew-x86 
curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew-x86
arch -x86_64 homebrew-x86/bin/brew install mysql-client@5.7
rm -rf ~/Library/Caches/pip
pip uninstall mysqlclient
export PATH="/opt/homebrew-x86/opt/mysql-client@5.7/bin:$PATH"
CPPFLAGS="-I/opt/homebrew-x86/opt/openssl@1.1/include" LDFLAGS="-L/opt/homebrew-x86/opt/openssl@1.1/lib" MYSQLCLIENT_CFLAGS="-I/opt/homebrew-x86/Cellar/mysql-client@5.7/5.7.32/include/mysql" MYSQLCLIENT_LDFLAGS="-L/opt/homebrew-x86/Cellar/mysql-client@5.7/5.7.32/lib -lmysqlclient" arch -x86_64 pip install -I -vvv mysqlclient

And then, again as jcbloch suggests, I verified the installation by checking that the mysql_affected_rows symbol is present. I guess that symbol only exists in the x86_64 architecture version of the MySQL client.

$ sudo symbols homebrew-x86/Cellar/mysql-client@5.7/5.7.34/lib/libmysqlclient.dylib -arch x86_64 | grep mysql_affected_rows
       0x0000000000003fe7 (     0xd) mysql_affected_rows [FUNC, EXT, NameNList, MangledNameNList, Merged, NList, FunctionStarts]
Kirby
  • 15,127
  • 10
  • 89
  • 104
  • 1
    On newer macs, python3.9 is preinstalled on `/opt/homebrew/bin/python3.9`, which is already arch arm64, so you don't need all these to force x86. I came here initially because i was trying to run it with python3.7, but your answer gave me that idea. :) – Carlos.V Mar 02 '22 at 02:18
  • unfortunately i need python 2. yeah, I know, that's the dark ages. – Kirby Mar 02 '22 at 04:18
0

I hope this helps one or the other who did not get further with the answers. I have tried all solutions and the only thing that has helped me is the following.

First the answer from @sathira lamal with the combination of "brew".

the two commands are:

1 : brew install mysql

2 : pip install mysqlclient

Om Alba
  • 44
  • 7
0

I solve this error by first installing gcc and then mysql-client

brew install gcc

and then,

brew install mysql-client

Deepanshu Mehta
  • 1,119
  • 12
  • 9
-2

Look at this link

I am using M1 Macbook and I had the same problem and i solved this problem with PyMySQL using django 4.0.1 and python 3.10

  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/30865986) – Flair Jan 23 '22 at 21:59