Skip to content
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

failed to install: pip install mysqlclient (MySQL 8.0.33) #584

Closed
giuseppenovielli opened this issue May 6, 2023 · 16 comments · Fixed by #586
Closed

failed to install: pip install mysqlclient (MySQL 8.0.33) #584

giuseppenovielli opened this issue May 6, 2023 · 16 comments · Fixed by #586

Comments

@giuseppenovielli
Copy link

giuseppenovielli commented May 6, 2023

Describe the bug

When try into virtualenv but also in global environments -> pip install mysqlclient
failed to install with the follow stacktrace:

Collecting mysqlclient
  Using cached mysqlclient-2.1.1.tar.gz (88 kB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: mysqlclient
  Building wheel for mysqlclient (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [43 lines of output]
      mysql_config --version
      ['8.0.33']
      mysql_config --libs
      ['-L/opt/homebrew/opt/mysql-client/lib', '-lmysqlclient', '-lzlib', '-lzstd', '-L/opt/homebrew/opt/openssl@1.1/lib', '-lssl', '-lcrypto', '-lresolv']
      mysql_config --cflags
      ['-I/opt/homebrew/opt/mysql-client/include/mysql']
      ext_options:
        library_dirs: ['/opt/homebrew/opt/mysql-client/lib', '/opt/homebrew/opt/openssl@1.1/lib']
        libraries: ['mysqlclient', 'zlib', 'resolv']
        extra_compile_args: ['-std=c99']
        extra_link_args: []
        include_dirs: ['/opt/homebrew/opt/mysql-client/include/mysql']
        extra_objects: []
        define_macros: [('version_info', "(2,1,1,'final',0)"), ('__version__', '2.1.1')]
      running bdist_wheel
      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
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -iwithsysroot/System/Library/Frameworks/System.framework/PrivateHeaders -iwithsysroot/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/Headers -arch arm64 -arch x86_64 -Werror=implicit-function-declaration -Dversion_info=(2,1,1,'final',0) -D__version__=2.1.1 -I/opt/homebrew/opt/mysql-client/include/mysql -I/Users/hrcoffee6/my_venv/django_3/include -I/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.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
      clang -bundle -undefined dynamic_lookup -arch arm64 -arch x86_64 -Wl,-headerpad,0x1000 build/temp.macosx-10.9-universal2-3.9/MySQLdb/_mysql.o -L/opt/homebrew/opt/mysql-client/lib -L/opt/homebrew/opt/openssl@1.1/lib -lmysqlclient -lzlib -lresolv -o build/lib.macosx-10.9-universal2-3.9/MySQLdb/_mysql.cpython-39-darwin.so
      ld: library not found for -lzlib
      clang: error: linker command failed with exit code 1 (use -v to see invocation)
      error: command '/usr/bin/clang' failed with exit code 1
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for mysqlclient
  Running setup.py clean for mysqlclient
Failed to build mysqlclient
ERROR: Could not build wheels for mysqlclient, which is required to install pyproject.toml-based projects

Environment

Macbook Pro M2
Python 3.9.6

MySQL Server

  • 8.0.33 (Homebrew)

MySQL Client

  • OS (MacOS Ventura 13.3.1 (a)):

Additional context

brew install mysqlclient -> installed successfully

https://stackoverflow.com/questions/76177559/library-not-found-for-lzlib-mac-m2-chip-pip-install-mysqlclient

@giuseppenovielli giuseppenovielli changed the title MacOS Ventura 13.3.1 (a) failed to install: pip install mysqlclient MacOS Ventura 13.3.1 (a) Macbook Pro M2, failed to install: pip install mysqlclient May 6, 2023
@giuseppenovielli
Copy link
Author

giuseppenovielli commented May 6, 2023

it seems mysql 8.0.33 issue -> Homebrew/homebrew-core#130258

WORKAROUND -> if you use Django:

Use Oracle MySQL Connector/Python
(https://docs.djangoproject.com/en/4.2/ref/databases/#mysql-db-api-drivers

1)Download https://dev.mysql.com/downloads/connector/python/
2)DATABASES = { 'default': { 'ENGINE': 'mysql.connector.django', 'NAME': '<name_db>', 'USER': '<user_db>', 'PASSWORD': '<pass_db>', 'HOST': 'localhost', 'PORT': '3306', } }

@methane
Copy link
Member

methane commented May 7, 2023

It seems MySQL bug. They break mysql_config often.

@JeongtaekLim
Copy link

I've tried almost all available solutions on google and failed.
M2 Ventura is eating my 3hours..

@methane
Copy link
Member

methane commented May 7, 2023

$ export MYSQLCLIENT_LDFLAGS=$(pkg-config --libs mysqlclient)
$ export MYSQLCLIENT_CFLAGS=$(pkg-config --cflags mysqlclient)
$ pip install mysqlclient

@ozquez
Copy link

ozquez commented May 7, 2023

@methane , Adding those variables worked for me. Thanks!

@sunrongxin7666
Copy link

@methane Thanks a lot! It works for me.

@fmuradov
Copy link

fmuradov commented May 8, 2023

Thanks @methane, it works for me also!

@methane methane pinned this issue May 8, 2023
@methane methane changed the title MacOS Ventura 13.3.1 (a) Macbook Pro M2, failed to install: pip install mysqlclient failed to install: pip install mysqlclient (MySQL 8.0.33) May 8, 2023
@2twenity
Copy link

2twenity commented May 8, 2023

@methane
got message "zsh: command not found: pkg-config"
what could be the problem?

@methane
Copy link
Member

methane commented May 9, 2023

Do Google. I don't know your environment.

@methane methane closed this as completed in 14538b2 May 9, 2023
@giuseppenovielli
Copy link
Author

giuseppenovielli commented May 9, 2023

@2twenity

mac os global environment run: ->
brew install pkg-config

in your virtualenv or other environment ->

export MYSQLCLIENT_LDFLAGS=$(pkg-config --libs mysqlclient)
export MYSQLCLIENT_CFLAGS=$(pkg-config --cflags mysqlclient)
pip install mysqlclient

@2twenity
Copy link

2twenity commented May 9, 2023

@giuseppenovielli This worked! Thank you

@Sayed-Afnan-Khazi
Copy link

This worked, thank you so much!!

@methane
Copy link
Member

methane commented May 19, 2023

I have released 2.2.0rc1 that uses pkg-config instead of broken mysql_config.
Please try it.
https://pypi.org/project/mysqlclient/2.2.0rc1/

@rogervila
Copy link

2.2.0rc1 is fixed, following @methane previews post:

# ensure pkg-config is installed
brew install pkg-config

# Follow https://pypi.org/project/mysqlclient/2.2.0rc1/ "macOS (Homebrew)" section instructions
export PKG_CONFIG_PATH="/opt/homebrew/opt/mysql-client/lib/pkgconfig"

# 2.2.0rc1 installation works
pip install --no-cache mysqlclient==2.2.0rc1

@statsconchris
Copy link

statsconchris commented Jun 23, 2023

To have a complete solution in linux... try this

apt install pkg-config
export MYSQLCLIENT_LDFLAGS=$(pkg-config --libs mysqlclient)
export MYSQLCLIENT_CFLAGS=$(pkg-config --cflags mysqlclient)
pip install mysqlclient --no-cache-dir

or as stated in the official page

apt install -y pkg-config                                  
export MYSQLCLIENT_CFLAGS=`pkg-config mysqlclient --cflags`
export MYSQLCLIENT_LDFLAGS=`pkg-config mysqlclient --libs` 
pip3 install mysqlclient --no-cache-dir                    

@methane
Copy link
Member

methane commented Jun 23, 2023

No need to set MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS if pkg-config works.

@PyMySQL PyMySQL locked as resolved and limited conversation to collaborators Jun 23, 2023
@methane methane unpinned this issue Jul 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants