티스토리 뷰

Deployment

[PIP/PostgreSQL] psycopg2 설치 에러

angieveloper 2022. 4. 20. 16:10
$ pip3 install postgres

위 명령어 실행시 발생하는 에러 해결하기

 

⛳️ 1. 로컬에 PostgreSQL이 설치되어 있지 않은 경우

(1) MacOS

$ brew install postgresql

(2) Ubuntu

$ sudo apt-get install postgresql postgresql-contrib libpq-dev

 

아래 사이트에서 ubuntu 설치 패키지 확인 한 번하는 걸 추천한다

https://www.postgresql.org/download/linux/ubuntu/

 

PostgreSQL: Linux downloads (Ubuntu)

Linux downloads (Ubuntu) PostgreSQL is available in all Ubuntu versions by default. However, Ubuntu "snapshots" a specific version of PostgreSQL that is then supported throughout the lifetime of that Ubuntu version. Other versions of PostgreSQL are availab

www.postgresql.org

 

⛳️ 2. Mac에서 환경변수가 설정되어 있지 않은 경우

엄청 길고 빨갛고(...) 심리적으로 위축되는 에러가 발생한다

Installing collected packages: psycopg2
  Running setup.py install for psycopg2 ... error
    ERROR: Command errored out with exit status 1:
     command: /Users/{사용자명}/{python3 가상환경}/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/fc/wlcrndtd1f1csk0wxkc4t4bm0000gp/T/pip-install-nxpzdtc6/psycopg2/setup.py'"'"'; __file__='"'"'/private/var/folders/fc/wlcrndtd1f1csk0wxkc4t4bm0000gp/T/pip-install-nxpzdtc6/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/fc/wlcrndtd1f1csk0wxkc4t4bm0000gp/T/pip-record-exhyhuli/install-record.txt --single-version-externally-managed --compile --install-headers /Users/sngeunjng/venv/include/site/python3.8/psycopg2
         cwd: /private/var/folders/fc/wlcrndtd1f1csk0wxkc4t4bm0000gp/T/pip-install-nxpzdtc6/psycopg2/

(...생략...)

ld: library not found for -lssl
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /Users/{사용자명}/{python3 가상환경}/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/fc/wlcrndtd1f1csk0wxkc4t4bm0000gp/T/pip-install-nxpzdtc6/psycopg2/setup.py'"'"'; __file__='"'"'/private/var/folders/fc/wlcrndtd1f1csk0wxkc4t4bm0000gp/T/pip-install-nxpzdtc6/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/fc/wlcrndtd1f1csk0wxkc4t4bm0000gp/T/pip-record-exhyhuli/install-record.txt --single-version-externally-managed --compile --install-headers /Users/sngeunjng/venv/include/site/python3.8/psycopg2 Check the logs for full command output.

 

환경변수를 설정해주면 쉽게 해결된다

 

(1) pg_config의 위치를 찾아야 한다.

$ which pg_config
/usr/local/bin/pg_config

 

(2) 위에서 찾은 pg_config의 위치 환경변수 설정

$ export PATH=$PATH:/usr/local/bin/

/usr/local/bin는 (1)에서 나온 결과에서 pg_config 빼고 써주면 된다

 

(3) openssl 라이브러리 연결 (ld: library not found for -lssl 해결)

$ export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/

위의 세 단계를 꼭! 모두 해주면 해결 가능하다.

 

⛳️ 3. Ubuntu에서 에러나는 경우

Collecting psycopg2==2.8.6
  Downloading psycopg2-2.8.6.tar.gz (383 kB)
     |████████████████████████████████| 383 kB 1.1 MB/s 
ERROR: Command errored out with exit status 1:
Error: b'You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.\n'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

 

 

아래와 같이 클라이언트 애플리케이션 설치해주기

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

 

 

 

예전에 다른 블로그에 정리해뒀던 에러 이슈

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함