使用postgresql數據庫一直都是在服務器同一台機子上,所以一向都正常,今天在其他服務器上調用,執行pip3 install psycopg2后直接暴下面錯誤:
[root@slave2 ~]# pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple/ psycopg2
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple/
Collecting psycopg2
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/84/d7/6a93c99b5ba4d4d22daa3928b983cec66df4536ca50b22ce5dcac65e4e71/psycopg2-2.8.4.tar.gz (377 kB)
ERROR: Command errored out with exit status 1:
command: /usr/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-v70fvqse/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-v70fvqse/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-v70fvqse/psycopg2/pip-egg-info
cwd: /tmp/pip-install-v70fvqse/psycopg2/
Complete output (23 lines):
running egg_info
creating /tmp/pip-install-v70fvqse/psycopg2/pip-egg-info/psycopg2.egg-info
writing /tmp/pip-install-v70fvqse/psycopg2/pip-egg-info/psycopg2.egg-info/PKG-INFO
writing dependency_links to /tmp/pip-install-v70fvqse/psycopg2/pip-egg-info/psycopg2.egg-info/dependency_links.txt
writing top-level names to /tmp/pip-install-v70fvqse/psycopg2/pip-egg-info/psycopg2.egg-info/top_level.txt
writing manifest file '/tmp/pip-install-v70fvqse/psycopg2/pip-egg-info/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
<http://initd.org/psycopg/docs/install.html>).
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
按錯誤提示,登錄提示地址 http://initd.org/psycopg/docs/install.html 進行查看
發現原來安裝psycopg2需要先安裝postgresql服務
Prerequisites The current psycopg2 implementation supports: Python version 2.7 Python 3 versions from 3.4 to 3.8 PostgreSQL server versions from 7.4 to 12 PostgreSQL client library version from 9.1
然后按照要求安裝好了ps數據庫相關服務
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm yum install postgresql11 yum install postgresql11-server yum install postgresql11-libs yum install postgresql11-contrib yum install postgresql11-devel
安裝完成后執行pip安裝,還是出錯,重新認真查看官網的安裝要求后,發現還需要配置 pg_config 路徑(這里有點奇怪,我以前在有的服務器上並沒有做這個設置,安裝也是正常)
按要求在服務器上執行了下面命令:
export PATH=/usr/pgsql-11/bin/:$PATH
然后再執行pip安裝psycopg2
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple/ psycopg2
安裝成功
[root@slave2 bin]# export PATH=/usr/pgsql-11/bin/:$PATH
[root@slave2 bin]# pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple/ psycopg2
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple/
Collecting psycopg2
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/84/d7/6a93c99b5ba4d4d22daa3928b983cec66df4536ca50b22ce5dcac65e4e71/psycopg2-2.8.4.tar.gz (377 kB)
|████████████████████████████████| 377 kB 4.8 MB/s
Building wheels for collected packages: psycopg2
Building wheel for psycopg2 (setup.py) ... done
Created wheel for psycopg2: filename=psycopg2-2.8.4-cp37-cp37m-linux_x86_64.whl size=382831 sha256=b2d2c502b6d15be05d06f9fa0864de1e5a46874658939a329e4f08c1f68c925d
Stored in directory: /root/.cache/pip/wheels/15/11/c5/8f06c23a46a3162b3756d2132a5c5dd4c2edb204049d59ae93
Successfully built psycopg2
Installing collected packages: psycopg2
Successfully installed psycopg2-2.8.4
