pip3安装包时候的异常处理
报错信息如下
# pip3 install psycopg2
Collecting psycopg2
Downloading https://files.pythonhosted.org/packages/fd/ae/98cb7a0cbb1d748ee547b058b14604bd0e9bf285a8e0cc5d148f8a8a952e/psycopg2-2.8.6.tar.gz (383kB)
100% |████████████████████████████████| 389kB 2.3MB/s
Building wheels for collected packages: psycopg2
Running setup.py bdist_wheel for psycopg2 ... error
Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-6opkdiqe/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/tmpcg0csrfqpip-wheel- --python-tag cp35:
/usr/lib/python3.5/distutils/dist.py:261: UserWarning: Unknown distribution option: 'project_urls'
warnings.warn(msg)
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.5
creating build/lib.linux-x86_64-3.5/psycopg2
copying lib/_range.py -> build/lib.linux-x86_64-3.5/psycopg2
copying lib/sql.py -> build/lib.linux-x86_64-3.5/psycopg2
copying lib/_lru_cache.py -> build/lib.linux-x86_64-3.5/psycopg2
copying lib/errorcodes.py -> build/lib.linux-x86_64-3.5/psycopg2
copying lib/extensions.py -> build/lib.linux-x86_64-3.5/psycopg2
copying lib/__init__.py -> build/lib.linux-x86_64-3.5/psycopg2
copying lib/pool.py -> build/lib.linux-x86_64-3.5/psycopg2
copying lib/_json.py -> build/lib.linux-x86_64-3.5/psycopg2
copying lib/_ipaddress.py -> build/lib.linux-x86_64-3.5/psycopg2
copying lib/extras.py -> build/lib.linux-x86_64-3.5/psycopg2
copying lib/compat.py -> build/lib.linux-x86_64-3.5/psycopg2
copying lib/tz.py -> build/lib.linux-x86_64-3.5/psycopg2
copying lib/errors.py -> build/lib.linux-x86_64-3.5/psycopg2
running build_ext
building 'psycopg2._psycopg' extension
creating build/temp.linux-x86_64-3.5
creating build/temp.linux-x86_64-3.5/psycopg
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.5-5Cvh2K/python3.5-3.5.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=140003 -DHAVE_LO64=1 -I/usr/include/python3.5m -I. -I/usr/include/postgresql -I/usr/include/postgresql/14/server -c psycopg/psycopgmodule.c -o build/temp.linux-x86_64-3.5/psycopg/psycopgmodule.o -Wdeclaration-after-statement
In file included from psycopg/psycopgmodule.c:28:0:
./psycopg/psycopg.h:36:22: fatal error: libpq-fe.h: No such file or directory
#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
----------------------------------------
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
Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-6opkdiqe/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-ki8ms03h-record/install-record.txt --single-version-externally-managed --compile:
/usr/lib/python3.5/distutils/dist.py:261: UserWarning: Unknown distribution option: 'project_urls'
warnings.warn(msg)
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.5
creating build/lib.linux-x86_64-3.5/psycopg2
copying lib/_range.py -> build/lib.linux-x86_64-3.5/psycopg2
copying lib/sql.py -> build/lib.linux-x86_64-3.5/psycopg2
copying lib/_lru_cache.py -> build/lib.linux-x86_64-3.5/psycopg2
copying lib/errorcodes.py -> build/lib.linux-x86_64-3.5/psycopg2
copying lib/extensions.py -> build/lib.linux-x86_64-3.5/psycopg2
copying lib/__init__.py -> build/lib.linux-x86_64-3.5/psycopg2
copying lib/pool.py -> build/lib.linux-x86_64-3.5/psycopg2
copying lib/_json.py -> build/lib.linux-x86_64-3.5/psycopg2
copying lib/_ipaddress.py -> build/lib.linux-x86_64-3.5/psycopg2
copying lib/extras.py -> build/lib.linux-x86_64-3.5/psycopg2
copying lib/compat.py -> build/lib.linux-x86_64-3.5/psycopg2
copying lib/tz.py -> build/lib.linux-x86_64-3.5/psycopg2
copying lib/errors.py -> build/lib.linux-x86_64-3.5/psycopg2
running build_ext
building 'psycopg2._psycopg' extension
creating build/temp.linux-x86_64-3.5
creating build/temp.linux-x86_64-3.5/psycopg
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.5-5Cvh2K/python3.5-3.5.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=140003 -DHAVE_LO64=1 -I/usr/include/python3.5m -I. -I/usr/include/postgresql -I/usr/include/postgresql/14/server -c psycopg/psycopgmodule.c -o build/temp.linux-x86_64-3.5/psycopg/psycopgmodule.o -Wdeclaration-after-statement
In file included from psycopg/psycopgmodule.c:28:0:
./psycopg/psycopg.h:36:22: fatal error: libpq-fe.h: No such file or directory
#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
----------------------------------------
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-6opkdiqe/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-ki8ms03h-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-6opkdiqe/psycopg2/
copying cffi/ffiplatform.py -> build/lib.linux-x86_64-3.7/cffi
copying cffi/__init__.py -> build/lib.linux-x86_64-3.7/cffi
copying cffi/model.py -> build/lib.linux-x86_64-3.7/cffi
copying cffi/recompiler.py -> build/lib.linux-x86_64-3.7/cffi
copying cffi/api.py -> build/lib.linux-x86_64-3.7/cffi
copying cffi/_cffi_include.h -> build/lib.linux-x86_64-3.7/cffi
copying cffi/parse_c_type.h -> build/lib.linux-x86_64-3.7/cffi
copying cffi/_embedding.h -> build/lib.linux-x86_64-3.7/cffi
copying cffi/_cffi_errors.h -> build/lib.linux-x86_64-3.7/cffi
running build_ext
building '_cffi_backend' extension
creating build/temp.linux-x86_64-3.7
creating build/temp.linux-x86_64-3.7/c
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/usr/include/python3.7m -c c/_cffi_backend.c -o build/temp.linux-x86_64-3.7/c/_cffi_backend.o
[proxychains] DLL init: proxychains-ng 4.15
[proxychains] DLL init: proxychains-ng 4.15
c/_cffi_backend.c:15:10: fatal error: ffi.h: No such file or directory
#include <ffi.h>
^~~~~~~
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-zzoehyo1/cffi/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-bowz6rjy/install-record.txt --single-version-externally-managed --prefix /tmp/pip-build-env-31eykgev --compile" failed with error code 1 in /tmp/pip-install-zzoehyo1/cffi/
----------------------------------------
Command "/usr/bin/python3 -m pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-31eykgev --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- setuptools>=40.8.0 wheel "cffi>=1.4.1; python_implementation != 'PyPy'"" failed with error code 1 in None
处理办法:
apt-get install build-essential apt-get install python3-setuptools apt-get install python3-dev apt-get install python3-cffi apt-get install libpq-dev pip3 install --upgrade pip
