Python2.7 CentOS7 处理报错 ImportError: No module named psycopg2

运行出错:ImportError: No module named psycopg2
import psycopg2
Traceback (most recent call last):
File “”, line 1, in
ImportError: No module named psycopg2

安装出错:

[root@localhost pyscript]# pip install psycopg2
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Looking in indexes: http://mirrors.cloud.aliyuncs.com/pypi/simple/
Collecting psycopg2
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/fd/ae/98cb7a0cbb1d748ee547b058b14604bd0e9bf285a8e0cc5d148f8a8a952e/psycopg2-2.8.6.tar.gz (383 kB)
|████████████████████████████████| 383 kB 15.5 MB/s
ERROR: Command errored out with exit status 1:
command: /usr/bin/python -c ‘import sys, setuptools, tokenize; sys.argv[0] = ‘"’"’/tmp/pip-install-zXoKIr/psycopg2/setup.py’“'”‘; file=’“'”‘/tmp/pip-install-zXoKIr/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-pip-egg-info-1DZX3c
cwd: /tmp/pip-install-zXoKIr/psycopg2/
Complete output (25 lines):
/usr/lib64/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: ‘project_urls’
warnings.warn(msg)
running egg_info
creating /tmp/pip-pip-egg-info-1DZX3c/psycopg2.egg-info
writing /tmp/pip-pip-egg-info-1DZX3c/psycopg2.egg-info/PKG-INFO
writing top-level names to /tmp/pip-pip-egg-info-1DZX3c/psycopg2.egg-info/top_level.txt
writing dependency_links to /tmp/pip-pip-egg-info-1DZX3c/psycopg2.egg-info/dependency_links.txt
writing manifest file ‘/tmp/pip-pip-egg-info-1DZX3c/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
https://www.psycopg.org/docs/install.html).

……………………………………

ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output

# Python 2.7.6:
$ wget http://python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz
$ tar xf Python-2.7.6.tar.xz
$ cd Python-2.7.6
$ ./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
$ make && make altinstall
$ yum install postgresql-libs

# First get the setup script for Setuptools:
$ wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py

# Then install it for Python 2.7 and/or Python 3.3:
$ python2.7 ez_setup.py

$ easy_install-2.7 psycopg2

安装 ez_setup.py setuptools

#setuptools:

可以先打开setuptools的python官网看看setuptools软件包如何安装:

> wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py > python ez_setup.py --user

也可以下载setuptools软件包后安装:
(1)下载setuptools包

# wget http://pypi.python.org/packages/source/s/setuptools/setuptools-2.0.tar.gz
(2)解压setuptools包
# tar zxvf setuptools-2.0.tar.gz

(3)切换到当前文件夹

# cd setuptools-2.0
(4)编译setuptools
#python setup.py build

(5)开始执行setuptools安装

#python setup.py install

[root@localhost pyscript]# python
Python 2.7.5 (default, Jun 20 2019, 20:27:34) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
Traceback (most recent call last):
  File "", line 1, in <module>
ImportError: No module named psycopg2

解决步骤 1、

sudo  pip install psycopg2 

解决步骤 2、

sudo  pip install psycopg2-binary  

完成。

你可能感兴趣的:(PostgreSQL,CentOS,Linux,python,pycharm,tensorflow)