반응형
WSL에서 psycopg2 설치 시 에러 정리
psycopg2 파이썬 라이브러리를 설치할 때 에러 대응방법 정리
$ pip install psycopg2
아래와 같이 libpq-dev파일을 찾을 수 없어 설치가 안되는 경우가 있다.
Collecting psycopg2>=2.9.1
Using cached psycopg2-2.9.9.tar.gz (384 kB)
Building wheels for collected packages: psycopg2
Building wheel for psycopg2 (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /root/00_PRJ/dev_group/LMS_django_react/backend/.venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-p4rwwku3/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-p4rwwku3/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-hi_npvki
cwd: /tmp/pip-install-p4rwwku3/psycopg2/
Complete output (38 lines):
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.8
creating build/lib.linux-x86_64-3.8/psycopg2
copying lib/_ipaddress.py -> build/lib.linux-x86_64-3.8/psycopg2
copying lib/_range.py -> build/lib.linux-x86_64-3.8/psycopg2
copying lib/_json.py -> build/lib.linux-x86_64-3.8/psycopg2
copying lib/sql.py -> build/lib.linux-x86_64-3.8/psycopg2
copying lib/extensions.py -> build/lib.linux-x86_64-3.8/psycopg2
copying lib/__init__.py -> build/lib.linux-x86_64-3.8/psycopg2
copying lib/errors.py -> build/lib.linux-x86_64-3.8/psycopg2
copying lib/extras.py -> build/lib.linux-x86_64-3.8/psycopg2
copying lib/pool.py -> build/lib.linux-x86_64-3.8/psycopg2
copying lib/errorcodes.py -> build/lib.linux-x86_64-3.8/psycopg2
copying lib/tz.py -> build/lib.linux-x86_64-3.8/psycopg2
running build_ext
building 'psycopg2._psycopg' extension
creating build/temp.linux-x86_64-3.8
creating build/temp.linux-x86_64-3.8/psycopg
x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DPSYCOPG_VERSION=2.9.9 (dt dec pq3 ext lo64) -DPSYCOPG_DEBUG=1 -DPG_VERSION_NUM=120018 -DHAVE_LO64=1 -DPSYCOPG_DEBUG=1 -I/root/00_PRJ/dev_group/LMS_django_react/backend/.venv/include -I/usr/include/python3.8 -I. -I/usr/include/postgresql -I/usr/include/postgresql/12/server -I/usr/include/libxml2 -I/usr/include/mit-krb5 -c psycopg/psycopgmodule.c -o build/temp.linux-x86_64-3.8/psycopg/psycopgmodule.o -Wdeclaration-after-statement
In file included from psycopg/psycopgmodule.c:28:
./psycopg/psycopg.h:36:10: fatal error: libpq-fe.h: No such file or directory
36 | #include <libpq-fe.h>
| ^~~~~~~~~~~~
compilation terminated.
It appears you are missing some prerequisite to build the package from source.
You may install a binary package by installing 'psycopg2-binary' from PyPI.
If you want to install psycopg2 from source, please install the packages
required for the build and try again.
For further information please check the 'doc/src/install.rst' file (also at
<https://www.psycopg.org/docs/install.html>).
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
ERROR: Failed building wheel for psycopg2
Running setup.py clean for psycopg2
Failed to build psycopg2
Installing collected packages: psycopg2
Running setup.py install for psycopg2 ... error
ERROR: Command errored out with exit status 1:
command: /root/00_PRJ/dev_group/LMS_django_react/backend/.venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-p4rwwku3/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-p4rwwku3/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 /tmp/pip-record-lyn28y6e/install-record.txt --single-version-externally-managed --compile --install-headers /root/00_PRJ/dev_group/LMS_django_react/backend/.venv/include/site/python3.8/psycopg2
cwd: /tmp/pip-install-p4rwwku3/psycopg2/
Complete output (38 lines):
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.8
creating build/lib.linux-x86_64-3.8/psycopg2
copying lib/_ipaddress.py -> build/lib.linux-x86_64-3.8/psycopg2
copying lib/_range.py -> build/lib.linux-x86_64-3.8/psycopg2
copying lib/_json.py -> build/lib.linux-x86_64-3.8/psycopg2
copying lib/sql.py -> build/lib.linux-x86_64-3.8/psycopg2
copying lib/extensions.py -> build/lib.linux-x86_64-3.8/psycopg2
copying lib/__init__.py -> build/lib.linux-x86_64-3.8/psycopg2
copying lib/errors.py -> build/lib.linux-x86_64-3.8/psycopg2
copying lib/extras.py -> build/lib.linux-x86_64-3.8/psycopg2
copying lib/pool.py -> build/lib.linux-x86_64-3.8/psycopg2
copying lib/errorcodes.py -> build/lib.linux-x86_64-3.8/psycopg2
copying lib/tz.py -> build/lib.linux-x86_64-3.8/psycopg2
running build_ext
building 'psycopg2._psycopg' extension
creating build/temp.linux-x86_64-3.8
creating build/temp.linux-x86_64-3.8/psycopg
x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DPSYCOPG_VERSION=2.9.9 (dt dec pq3 ext lo64) -DPSYCOPG_DEBUG=1 -DPG_VERSION_NUM=120018 -DHAVE_LO64=1 -DPSYCOPG_DEBUG=1 -I/root/00_PRJ/dev_group/LMS_django_react/backend/.venv/include -I/usr/include/python3.8 -I. -I/usr/include/postgresql -I/usr/include/postgresql/12/server -I/usr/include/libxml2 -I/usr/include/mit-krb5 -c psycopg/psycopgmodule.c -o build/temp.linux-x86_64-3.8/psycopg/psycopgmodule.o -Wdeclaration-after-statement
In file included from psycopg/psycopgmodule.c:28:
./psycopg/psycopg.h:36:10: fatal error: libpq-fe.h: No such file or directory
36 | #include <libpq-fe.h>
| ^~~~~~~~~~~~
compilation terminated.
It appears you are missing some prerequisite to build the package from source.
You may install a binary package by installing 'psycopg2-binary' from PyPI.
If you want to install psycopg2 from source, please install the packages
required for the build and try again.
For further information please check the 'doc/src/install.rst' file (also at
<https://www.psycopg.org/docs/install.html>).
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /root/00_PRJ/dev_group/LMS_django_react/backend/.venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-p4rwwku3/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-p4rwwku3/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 /tmp/pip-record-lyn28y6e/install-record.txt --single-version-externally-managed --compile --install-headers /root/00_PRJ/dev_group/LMS_django_react/backend/.venv/include/site/python3.8/psycopg2 Check the logs for full command output.
이 경우 libpq-dev를 아래의 명령으로 재설치 해보자 재 설치 후 정상적으로 설치되었음.
sudo apt-get install --reinstall libpq-dev
PostgreSQL 설치
또한 이 라이브러리는 postgresql adapter이다. postgresSQL이 설치되었는지도 확인해보자
sudo apt update
sudo apt install postgresql postgresql-contrib ( 패키지가 업데이트된 후에는 PostgreSQL(몇 가지 유용한 유틸리티가 포함된 -contrib 패키지)을 설치)
위의 명령으로 PostgreSQL 을 설치하고 버전 번호(psql --version)를 가져옵니다. 버전정보가 올바로 출력된다면 PostgreSQL이 정상설치된 상태입니다. PostgreSQL이 설치되면 다음 세 가지 명령으로 서비스 상태를 변경할 수 있습니다.
sudo service postgresql status: 데이터베이스의 상태 확인
sudo service postgresql start 데이터베이스 실행 시작
sudo service postgresql stop: 데이터베이스 실행 중지
반응형
'Programming' 카테고리의 다른 글
우분투에 Doxygen 설치 방법 (0) | 2024.06.05 |
---|---|
PATH, 환경변수 추가 - 리눅스 (0) | 2024.06.04 |
SQL에서 상위 비율 데이터 확인하기 (1) | 2024.05.31 |
SQL에서 중복을 제거하고 데이터를 조회 (0) | 2024.05.31 |
SQL 정렬 명령을 이용한 데이터 정렬 (0) | 2024.05.31 |