Mac M1芯片 pycharm安装mysqlclient报错解决

❯ pip install mysqlclient
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
  ╰─> [44 lines of output]
      mysql_config --version
      ['8.0.32']
      mysql_config --libs
      ['-L/usr/local/opt/mysql-client/lib', '-lmysqlclient', '-lz', '-L/usr/local/lib', '-lzstd', '-L/usr/local/opt/openssl@1.1/lib', '-lssl', '-lcrypto', '-lresolv']
      mysql_config --cflags
      ['-I/usr/local/opt/mysql-client/include/mysql']
      ext_options:
        library_dirs: ['/usr/local/opt/mysql-client/lib', '/usr/local/lib', '/usr/local/opt/openssl@1.1/lib']
        libraries: ['mysqlclient', 'resolv']
        extra_compile_args: ['-std=c99']
        extra_link_args: []
        include_dirs: ['/usr/local/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-cpython-39
      creating build/lib.macosx-10.9-universal2-cpython-39/MySQLdb
      copying MySQLdb/__init__.py -> build/lib.macosx-10.9-universal2-cpython-39/MySQLdb
      copying MySQLdb/_exceptions.py -> build/lib.macosx-10.9-universal2-cpython-39/MySQLdb
      copying MySQLdb/connections.py -> build/lib.macosx-10.9-universal2-cpython-39/MySQLdb
      copying MySQLdb/converters.py -> build/lib.macosx-10.9-universal2-cpython-39/MySQLdb
      copying MySQLdb/cursors.py -> build/lib.macosx-10.9-universal2-cpython-39/MySQLdb
      copying MySQLdb/release.py -> build/lib.macosx-10.9-universal2-cpython-39/MySQLdb
      copying MySQLdb/times.py -> build/lib.macosx-10.9-universal2-cpython-39/MySQLdb
      creating build/lib.macosx-10.9-universal2-cpython-39/MySQLdb/constants
      copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.9-universal2-cpython-39/MySQLdb/constants
      copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.9-universal2-cpython-39/MySQLdb/constants
      copying MySQLdb/constants/CR.py -> build/lib.macosx-10.9-universal2-cpython-39/MySQLdb/constants
      copying MySQLdb/constants/ER.py -> build/lib.macosx-10.9-universal2-cpython-39/MySQLdb/constants
      copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.9-universal2-cpython-39/MySQLdb/constants
      copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.9-universal2-cpython-39/MySQLdb/constants
      running build_ext
      building 'MySQLdb._mysql' extension
      creating build/temp.macosx-10.9-universal2-cpython-39
      creating build/temp.macosx-10.9-universal2-cpython-39/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 -Wno-error=unreachable-code -I/usr/local/opt/mysql-client/include -Dversion_info=(2,1,1,'final',0) -D__version__=2.1.1 -I/usr/local/opt/mysql-client/include/mysql -I/Users/albert/Site/F8CHAT/env/include -I/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/Headers -c MySQLdb/_mysql.c -o build/temp.macosx-10.9-universal2-cpython-39/MySQLdb/_mysql.o -std=c99
      MySQLdb/_mysql.c:46:10: fatal error: 'Python.h' file not found
      #include "Python.h"
               ^~~~~~~~~~
      1 error generated.
      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
Installing collected packages: mysqlclient
  Running setup.py install for mysqlclient ... error
  error: subprocess-exited-with-error
  
  × Running setup.py install for mysqlclient did not run successfully.
  │ exit code: 1
  ╰─> [46 lines of output]
      mysql_config --version
      ['8.0.32']
      mysql_config --libs
      ['-L/usr/local/opt/mysql-client/lib', '-lmysqlclient', '-lz', '-L/usr/local/lib', '-lzstd', '-L/usr/local/opt/openssl@1.1/lib', '-lssl', '-lcrypto', '-lresolv']
      mysql_config --cflags
      ['-I/usr/local/opt/mysql-client/include/mysql']
      ext_options:
        library_dirs: ['/usr/local/opt/mysql-client/lib', '/usr/local/lib', '/usr/local/opt/openssl@1.1/lib']
        libraries: ['mysqlclient', 'resolv']
        extra_compile_args: ['-std=c99']
        extra_link_args: []
        include_dirs: ['/usr/local/opt/mysql-client/include/mysql']
        extra_objects: []
        define_macros: [('version_info', "(2,1,1,'final',0)"), ('__version__', '2.1.1')]
      running install
      /Users/albert/Site/F8CHAT/env/lib/python3.9/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
        warnings.warn(
      running build
      running build_py
      creating build
      creating build/lib.macosx-10.9-universal2-cpython-39
      creating build/lib.macosx-10.9-universal2-cpython-39/MySQLdb
      copying MySQLdb/__init__.py -> build/lib.macosx-10.9-universal2-cpython-39/MySQLdb
      copying MySQLdb/_exceptions.py -> build/lib.macosx-10.9-universal2-cpython-39/MySQLdb
      copying MySQLdb/connections.py -> build/lib.macosx-10.9-universal2-cpython-39/MySQLdb
      copying MySQLdb/converters.py -> build/lib.macosx-10.9-universal2-cpython-39/MySQLdb
      copying MySQLdb/cursors.py -> build/lib.macosx-10.9-universal2-cpython-39/MySQLdb
      copying MySQLdb/release.py -> build/lib.macosx-10.9-universal2-cpython-39/MySQLdb
      copying MySQLdb/times.py -> build/lib.macosx-10.9-universal2-cpython-39/MySQLdb
      creating build/lib.macosx-10.9-universal2-cpython-39/MySQLdb/constants
      copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.9-universal2-cpython-39/MySQLdb/constants
      copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.9-universal2-cpython-39/MySQLdb/constants
      copying MySQLdb/constants/CR.py -> build/lib.macosx-10.9-universal2-cpython-39/MySQLdb/constants
      copying MySQLdb/constants/ER.py -> build/lib.macosx-10.9-universal2-cpython-39/MySQLdb/constants
      copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.9-universal2-cpython-39/MySQLdb/constants
      copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.9-universal2-cpython-39/MySQLdb/constants
      running build_ext
      building 'MySQLdb._mysql' extension
      creating build/temp.macosx-10.9-universal2-cpython-39
      creating build/temp.macosx-10.9-universal2-cpython-39/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 -Wno-error=unreachable-code -I/usr/local/opt/mysql-client/include -Dversion_info=(2,1,1,'final',0) -D__version__=2.1.1 -I/usr/local/opt/mysql-client/include/mysql -I/Users/albert/Site/F8CHAT/env/include -I/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/Headers -c MySQLdb/_mysql.c -o build/temp.macosx-10.9-universal2-cpython-39/MySQLdb/_mysql.o -std=c99
      MySQLdb/_mysql.c:46:10: fatal error: 'Python.h' file not found
      #include "Python.h"
               ^~~~~~~~~~
      1 error generated.
      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: legacy-install-failure

× Encountered error while trying to install package.
╰─> mysqlclient

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.
`


### Environment

**MySQL Client**

- OS (MacOS Ventura v13.3.1):

- Python (Homebrew Python 3.9.6):

- Connector/C (Homebrew mysql-client 8.0.18): 

如果报错以上内容那么就是你pycharm的环境出问题了 不要用mac自带的python 自己用homebrew下载python3.0 然后重新配置pycharm虚拟环境就可以了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值