programing

Mac + virtualenv + pip + postgresql = 오류 : pg_config 실행 파일을 찾을 수 없음

nasanasas 2020. 10. 25. 12:24
반응형

Mac + virtualenv + pip + postgresql = 오류 : pg_config 실행 파일을 찾을 수 없음


튜토리얼을 위해 postgres를 설치하려고했지만 pip오류가 발생합니다.

pip install psycopg

내가 얻는 오류의 일부 :

Error: pg_config executable not found.

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'.

pg_config내 가상 환경 은 어디에 있습니까 ? 어떻게 구성합니까? 시스템 전체에 postgres를 설치하고 싶지 않기 때문에 virtualenv를 사용하고 있습니다.


Mac에서 Postgres.app을 사용 하는 경우 pg_config 파일은 /Applications/Postgres.app/Contents/Versions/<current_version>/bin디렉터리에 있습니다. 이 오류를 수정하려면 다음과 같이 시스템 경로에 추가해야합니다.

export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/<current_version>/bin

예를 들어 현재 Postgres.app 버전이 9.5 인 경우이 내보내기 행은 다음과 같습니다.

export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.5/bin

최신 버전의 Postgres.app (> 9.5?)에서는 다음과 같이 버전 번호 대신 "최신"을 추가 할 수 있습니다.

export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin

Mac에서 해결책은 다음을 설치하는 것입니다 postgresql.

brew install postgresql

CentOS에서 해결책은 다음을 설치하는 것입니다 postgresql-devel.

sudo yum install postgresql-devel

pg_configpostgresql-devel패키지


나는 대부분의 게시 된 답변이 OP가 virtualenv 사용에 대한 요구를 정확히 지정했다고 가정하고 완전히 주제를 벗어났다는 john hight에 전적으로 동의합니다 .

나에게 대답은 virtualenv를 활성화하는 동안 프롬프트에서 다음 명령을 실행했습니다.

export PATH="/Applications/Postgres.app/Contents/Versions/9.4/bin:$PATH"

(파트 9.4는 버전을 나타내며 다를 수 있습니다.)

또는 최신 설치된 Postgres 버전 을 사용하려는 경우 :

export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH" 

그리고:

pip install psycopg2

postgres를 설치했다고 가정합니다. 그렇지 않은 경우 가장 좋고 권장되는 솔루션은 Postgres.app 을 사용하는 것임을 기억하십시오.


가상 환경의 $ PATH 변수! = 전역 $ PATH 변수를 잊지 마십시오. virtualenv와 새 셸에서 'echo $ PATH'로이를 확인할 수 있습니다. 따라서 가상 환경 내에서 고유 한 인스턴스로 PostgreSQL을 설치하지 않으려면 (할 가치가 없습니다. imo) virtualenv 내에서 $ PATH 변수를 수정하여 전역 설치 경로를 포함해야합니다. 누락 된 pg_config 오류를 해결하십시오).

단계는 다음과 같습니다.

1.) 새 셸에서 'which pg_config'를 입력합니다. 경로를 반환합니다. 복사하십시오. 제 경우 경로는 다음과 같습니다. /Applications/Postgres.app/Contents/Versions/9.3/bin

2.) virtualenv 셸로 돌아가서 'export PATH = / your-path-to-pg_config : $ PATH'를 입력합니다.

3.) 그런 다음 여전히 virtualenv 내에서 'pip install psycopg2'

모든 것이 계획대로 진행되면 가상 환경 내에 psycopg2가 설치되지만 설치는 Global PostgreSQL 설치를 참조합니다. 필자의 경우이 전역 설치는 Postgres.App을 통해 설치되었으므로 경로입니다. 정의 된 가상 환경 내에서만이 아니라 모든 virtualenv 내에서 쉽게 데이터베이스를 사용할 수 있다는 것을 의미하므로 psycopg2로 작업하는이 방법을 선호합니다.

여기에 도착하는 모든 사람에게 도움이되기를 바랍니다. Google juice의 경우 다음은이 문제가 발생할 때 반환되는 명시적이고 모호한 오류 언어입니다.
Command python setup.py egg_info failed with error code 1


Mac (OSX 10.9)에서이 문제를 해결하는 방법은 다음과 같습니다.

brew update
brew install --force ossp-uuid
brew install postgresql
pip install psycopg

시도 할 때 CLANG 오류 pip install psycopg( LLVM 5.1 문제 )가 발생하여 대신이 명령을 사용하여 psycopg를 설치해야했습니다.

ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install psycopg

Mingyu의 솔루션 과 비슷 하지만 공유 할 가치가 있다고 생각한 차이가 충분합니다.


이 오류는 빌드 도구가 Postgresql 라이브러리를 찾을 수 없을 때 발생합니다.

종종 psycopg2에게 pg_config 바이너리를 찾는 방법을 지시해야합니다. 다음을 수행 할 수 있습니다.

  1. 셸 경로 (/ usr / local / pgsql / bin /)에 pg_config에 대한 경로를 추가합니다.

  2. 또는 psycopg2 소스 폴더에서 setup.cfg 파일을 편집하고 pg_config =로 시작하는 줄에 pg_config의 전체 경로를 제공합니다.

pg_config = / usr / local / pgsql / bin / pg_config

  • 위의 예는 locate pg_config위치를 찾거나 단순히 입력 which pg_config하면 경로를 알려줄 수 있습니다.

Less often the error comes from not having postgresql installed on your system. If so, download and build postgres, or download a pre-built psycopg2 binary for OS X.


For OS X El Captain (10.11.6) + brew + virtualenv + PostgreSQL 9.5:

After installing PostgreSQL 9.5:

brew install postgresql@9.5

Open your terminal and execute:

export PATH=$PATH:/usr/local/opt/postgresql\@9.5/bin/
pip install psycopg2

On Windows I installed postgres manually from http://www.enterprisedb.com/products-services-training/pgdownload#windows. After that the same command works.


virtualenv is for python packages. I don't think you'll be able to contain postgres inside a virtualenv. The error message you're seeing is presumably because you haven't yet installed postgres. The psycopg2 install script is looking for postgres files (in this case pg_config) and not finding them because it is not installed. postgres can't be installed using pip or virtualenv.


In addition to the answers provided by @bkev and @andi, according to the documentation on Postgres.app, you should add the following to your bash_profile on Mac:

export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin

Note that, there is no hard-coded version number. I wanted to add this as a comment to above answers, but I don't have enough rep for this.


If you're using postgresql 9.4, the file is located in

/usr/pgsql-9.4/bin/pg_config

The name of the package is

postgresql94-9.4.9-1PGDG.rhel6.x86_64

to add pg_config to your PATH, do the following

PATH=$PATH:/usr/pgsql-9.4/bin/

On Ubuntu I just needed the postgres dev package:

sudo apt-get install postgresql-server-dev-all

Mine was located in /Library/PostgreSQL/9.4/bin

export PATH=$PATH:/Library/PostgreSQL/9.4/bin

If you don't have to use the psycopg driver specifically, switch to the pg8000 driver. It's pure Python and less finicky.

참고URL : https://stackoverflow.com/questions/20170895/mac-virtualenv-pip-postgresql-error-pg-config-executable-not-found

반응형