安装psycopg2出错问题处理记录

使用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

 

posted @ 2020-03-31 16:53  AllEmpty  阅读(2752)  评论(0编辑  收藏  举报