ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [Error] pg_config executable not found.
    Back/Python 2022. 10. 5. 16:59

    배경

    redshift 실습을 위해 psycopg2 모듈을 커맨드로 설치하던 중 발생

    pip install psycopg2

    Collecting psycopg2
      Downloading psycopg2-2.9.3.tar.gz (380 kB)
         ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 380.6/380.6 kB 6.7 MB/s eta 0:00:00
      Preparing metadata (setup.py) ... error
      error: subprocess-exited-with-error
    
      × python setup.py egg_info did not run successfully.
      │ exit code: 1
      ╰─> [20 lines of output]
          running egg_info
          creating /private/var/folders/ql/sxpb0jls2ks5nz5_7tw7rggm0000gn/T/pip-pip-egg-info-xie4l2ci/psycopg2.egg-info
          writing manifest file '/private/var/folders/ql/sxpb0jls2ks5nz5_7tw7rggm0000gn/T/pip-pip-egg-info-xie4l2ci/psycopg2.egg-info/SOURCES.txt'
    
          Error: pg_config executable not found.
    
          pg_config is required to build psycopg2 from source.  Please add the directory
          containing pg_config to the $PATH or specify the full executable path with the
          option:
    
              python setup.py build_ext --pg-config /path/to/pg_config build ...
    
          or with the pg_config option in 'setup.cfg'.
    
          If you prefer to avoid building psycopg2 from source, please install the PyPI
          'psycopg2-binary' package instead.
    
          For further information please check the 'doc/src/install.rst' file (also at
          <https://www.psycopg.org/docs/install.html>).
    
          [end of output]
    
      note: This error originates from a subprocess, and is likely not a problem with pip.
    error: metadata-generation-failed
    
    × Encountered error while generating package metadata.
    ╰─> See above for output.

    원인

      • Postgresql 설치가 안되어 pg_config 가 미 생성됨
        • which pg_config 조회 결과 없음
        • pg_config : 설치된 Postgresql 버전의 정보(매개변수)가 있는 도구

    해결

    • Postgresql 설치

      • (MAC) brew install postgresql
      • 가상환경일 경우

        • 환경변수 등록
          • wtich pg_config 참조하여 경로 복사
          • export PATH=$PATH:{pg_config path}
          • 참고
      • 프로덕션에서 사용하지 않는다면 psycopg2-binary 고려

        • pip install psycopg2-binary
        • 참고

    'Back > Python' 카테고리의 다른 글

    [Python] BeautifulSoup  (0) 2023.04.19
    [Python] selenium  (0) 2022.12.21
    [Python] requests  (0) 2022.12.20
Designed by Tistory.