Skip to content

Can't install mysqlclient on Mac M1 Big Sur (11.2.2) #497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
m-ketan opened this issue May 30, 2021 · 7 comments
Closed

Can't install mysqlclient on Mac M1 Big Sur (11.2.2) #497

m-ketan opened this issue May 30, 2021 · 7 comments

Comments

@m-ketan
Copy link

m-ketan commented May 30, 2021

Python: 3.9.5
mysql: 8.0.25

Trying to install mysqlclient for setting up connection with django but failing with the below output:

Collecting mysqlclient
  Using cached mysqlclient-2.0.3.tar.gz (88 kB)
Using legacy 'setup.py install' for mysqlclient, since package 'wheel' is not installed.
Installing collected packages: mysqlclient
    Running setup.py install for mysqlclient ... error
    ERROR: Command errored out with exit status 1:
     command: /Users/mketan/Documents/diit/diit_env/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/qm/kp4ls0ds5q7gh4rtfqy4xxrr0000gn/T/pip-install-fbu018c0/mysqlclient_64e4fa21b76648ff84f8c751e242384d/setup.py'"'"'; __file__='"'"'/private/var/folders/qm/kp4ls0ds5q7gh4rtfqy4xxrr0000gn/T/pip-install-fbu018c0/mysqlclient_64e4fa21b76648ff84f8c751e242384d/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/qm/kp4ls0ds5q7gh4rtfqy4xxrr0000gn/T/pip-record-3wl14yep/install-record.txt --single-version-externally-managed --compile --install-headers /Users/b0223621/Documents/diit/diit_env/include/site/python3.9/mysqlclient
         cwd: /private/var/folders/qm/kp4ls0ds5q7gh4rtfqy4xxrr0000gn/T/pip-install-fbu018c0/mysqlclient_64e4fa21b76648ff84f8c751e242384d/
    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-universal2-3.9
    creating build/lib.macosx-10.9-universal2-3.9/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb
    copying MySQLdb/_exceptions.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb
    copying MySQLdb/connections.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb
    copying MySQLdb/converters.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb
    copying MySQLdb/release.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb
    copying MySQLdb/times.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb
    creating build/lib.macosx-10.9-universal2-3.9/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.9-universal2-3.9/MySQLdb/constants
    running build_ext
    building 'MySQLdb._mysql' extension
    creating build/temp.macosx-10.9-universal2-3.9
    creating build/temp.macosx-10.9-universal2-3.9/MySQLdb
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -arch x86_64 -g -I/opt/homebrew/opt/zlib/include -I/opt/homebrew/opt/bzip2/include -I/opt/homebrew/opt/[email protected]/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/b0223621/Documents/diit/diit_env/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c MySQLdb/_mysql.c -o build/temp.macosx-10.9-universal2-3.9/MySQLdb/_mysql.o -std=c99
    gcc -bundle -undefined dynamic_lookup -arch arm64 -arch x86_64 -g -L/opt/homebrew/opt/zlib/lib -L/opt/homebrew/opt/bzip2/lib -L/opt/homebrew/opt/[email protected]/lib -I/opt/homebrew/opt/zlib/include -I/opt/homebrew/opt/bzip2/include -I/opt/homebrew/opt/[email protected]/include build/temp.macosx-10.9-universal2-3.9/MySQLdb/_mysql.o -L/opt/homebrew/Cellar/mysql/8.0.25_1/lib -lmysqlclient -lzstd -lresolv -o build/lib.macosx-10.9-universal2-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/b0223621/Documents/diit/diit_env/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/qm/kp4ls0ds5q7gh4rtfqy4xxrr0000gn/T/pip-install-fbu018c0/mysqlclient_64e4fa21b76648ff84f8c751e242384d/setup.py'"'"'; __file__='"'"'/private/var/folders/qm/kp4ls0ds5q7gh4rtfqy4xxrr0000gn/T/pip-install-fbu018c0/mysqlclient_64e4fa21b76648ff84f8c751e242384d/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/qm/kp4ls0ds5q7gh4rtfqy4xxrr0000gn/T/pip-record-3wl14yep/install-record.txt --single-version-externally-managed --compile --install-headers /Users/mketan/Documents/diit/diit_env/include/site/python3.9/mysqlclient Check the logs for full command output.
@danschae
Copy link

danschae commented Jun 6, 2021

I'm having the exact same issue, did you eventually manage to figure it out?

@danschae
Copy link

danschae commented Jun 7, 2021

So this isn't so much as a fix as an alternate solution but if you're running a virtual environment. Don't use a virtual environment, install python3 with homebrew and install mysql normally with homebrew, then pip3 install mysqlclient and it should work fine. It's not an ideal solution but it's worked for me so far.

@methane methane closed this as completed Jun 8, 2021
@luca-drf
Copy link

luca-drf commented Jun 8, 2021

Why closing this? It would be nice if macOS/brew virtualenvs were supported...

Anyway, as a workaround I was able to install in a virtualenv with:

brew install zstd
CFLAGS="-I$(brew --prefix)/include" LDFLAGS="-L$(brew --prefix)/lib" pip install mysqlclient

@jcbloch
Copy link

jcbloch commented Jul 19, 2021

it should be closed. it is not a pymysql issue, but rather a problem with intel python trying to access native mysl libs via mysqlclient (see, eg, #496)

@codeyourwayup
Copy link

i had exactly the same errors

@sugerent
Copy link

Please check here:
https://stackoverflow.com/questions/66669728/trouble-installing-mysql-client-on-mac

@yc913344706
Copy link

Why closing this? It would be nice if macOS/brew virtualenvs were supported...

Anyway, as a workaround I was able to install in a virtualenv with:

brew install zstd
CFLAGS="-I$(brew --prefix)/include" LDFLAGS="-L$(brew --prefix)/lib" pip install mysqlclient

so nice!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants