오늘의 Logs

[Mac m1-Sequoia] mysqlclient 오류 (pkg-config)

yoon.p 2024. 9. 28. 09:00

발생 환경

- mac m1

- Sequoia 15.0

- Python 3.12.4

- pip 24.2

 

django 설정 중 mysql 연결 과정에서 mysqlclient 설치시 발생한 에러와 해결법 공유드립니다. ( 에러 로그 내용 더보기 참고 )

더보기
(venv) ➜ ✗ pip install mysqlclient
Collecting mysqlclient
  Using cached mysqlclient-2.2.4.tar.gz (90 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error
  
  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [30 lines of output]
      /bin/sh: pkg-config: command not found
      /bin/sh: pkg-config: command not found
      /bin/sh: pkg-config: command not found
      Trying pkg-config --exists mysqlclient
      Command 'pkg-config --exists mysqlclient' returned non-zero exit status 127.
      Trying pkg-config --exists mariadb
      Command 'pkg-config --exists mariadb' returned non-zero exit status 127.
      Trying pkg-config --exists libmariadb
      Command 'pkg-config --exists libmariadb' returned non-zero exit status 127.
      Traceback (most recent call last):
        File "/venv/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/venv/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/venv/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
                 ^^^^^^^^^^^^^^^^^^^^^
        File "/private/var/folders/c9/k1r8_q5s3d3crwk8bmkbn02c0000gn/T/pip-build-env-0kt5c_2d/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 332, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=[])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/private/var/folders/c9/k1r8_q5s3d3crwk8bmkbn02c0000gn/T/pip-build-env-0kt5c_2d/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 302, in _get_build_requires
          self.run_setup()
        File "/private/var/folders/c9/k1r8_q5s3d3crwk8bmkbn02c0000gn/T/pip-build-env-0kt5c_2d/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 318, in run_setup
          exec(code, locals())
        File "<string>", line 155, in <module>
        File "<string>", line 49, in get_config_posix
        File "<string>", line 28, in find_package_name
      Exception: Can not find valid pkg-config name.
      Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manually
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

 

해당 에러의 경우 mysqlclient를 설치하는 동안 pkg-config가 설치되어 있지 않아서 발생한 문제로 보이며, 아래 문서 참고하여 해결할 수 있었습니다.

 

GitHub - PyMySQL/mysqlclient: MySQL/MariaDB connector for Python

MySQL/MariaDB connector for Python. Contribute to PyMySQL/mysqlclient development by creating an account on GitHub.

github.com

 

명령어만 참고한다면 아래와 같습니다.

 

- install MySQL and mysqlclient

$ # Assume you are activating Python 3 venv
$ brew install mysql pkg-config
$ pip install mysqlclient

 

- install mysql-client (without MySQL server)

$ # Assume you are activating Python 3 venv
$ brew install mysql-client pkg-config
$ export PKG_CONFIG_PATH="$(brew --prefix)/opt/mysql-client/lib/pkgconfig"
$ pip install mysqlclient

 

설정 방식에 따라 맞춰 진행추가 설치 필요하며, 설치 후 mysqlclient 정상적으로 설치되는 모습을 볼 수 있습니다.

 

이때 각자 환경에 따라 추가적인 설정이 필요할 수 있습니다.

참고: 공식 문서


 

혹시 잘못된 정보가 있거나 추가로 궁금한 사항이 있다면, 언제든지 댓글로 남겨주세요.

여러분의 소중한 피드백은 포스팅의 질을 향상하는데 큰 도움이 됩니다.

감사합니다!

 

 

'오늘의 Logs' 카테고리의 다른 글

[git] .gitignore 적용이 안되는 경우 해결법  (0) 2024.09.30