欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

安裝python依賴包psycopg2來調(diào)用postgresql的操作

 更新時間:2021年01月01日 08:56:25   作者:lee_moonj  
這篇文章主要介紹了安裝python依賴包psycopg2來調(diào)用postgresql的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

1、先安裝psycopg2的依賴組件

本案例的操作系統(tǒng)為linux red hat

在安裝python依賴包psycopg之前,你必須需要先安裝postgresql數(shù)據(jù)庫的相關(guān)組件:

postgresql-devel,postgresql,postgresql-libs這三個組件比較重要。另外,可選組件:postgresql-server

安裝上述組件之前,可以用命令來查看你的系統(tǒng)現(xiàn)在是否已經(jīng)安裝了相關(guān)組件:

[root@dthost27 ~]# rpm -qa | grep PostgreSQL

如果都沒有安裝,則可執(zhí)行命令如下:

[root@dthost27 ~]# yum install postgresql-devel

(安裝過程中會順帶安裝上postgresql和postgresql-libs組件)

2、安裝psycopg2依賴包

保證依賴組件存在后,就可以使用pip命令安裝了:

[root@dthost27 ~]# pip install psycopg2-binary

注:這里安裝的是binary格式的psycopg2依賴包,其實(shí)安裝psycopg2也可以,但是有時候執(zhí)行pip install psycopg2會報錯,而安裝psycopg2-binary(編譯后)則不會

啟動python測試

import psycopg2

補(bǔ)充:安裝psycopg2報錯_解決方案

報錯信息

(python3-virtualenv) [root@vl-bg-anaylsis02 extract_log]# pip3 install psycopg2
Collecting psycopg2
 Using cached psycopg2-2.8.4.tar.gz (377 kB)
  ERROR: Command errored out with exit status 1:
   command: /disk2/extract_log/python3-virtualenv/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-2d9wyu3k/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-2d9wyu3k/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-2d9wyu3k/psycopg2/pip-egg-info
     cwd: /tmp/pip-install-2d9wyu3k/psycopg2/
  Complete output (23 lines):
  running egg_info
  creating /tmp/pip-install-2d9wyu3k/psycopg2/pip-egg-info/psycopg2.egg-info
  writing /tmp/pip-install-2d9wyu3k/psycopg2/pip-egg-info/psycopg2.egg-info/PKG-INFO
  writing dependency_links to /tmp/pip-install-2d9wyu3k/psycopg2/pip-egg-info/psycopg2.egg-info/dependency_links.txt
  writing top-level names to /tmp/pip-install-2d9wyu3k/psycopg2/pip-egg-info/psycopg2.egg-info/top_level.txt
  writing manifest file '/tmp/pip-install-2d9wyu3k/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.

解決方案 For ubuntu

sudo apt-get install libpq-dev python3-dev

解決方案 For Fedora/Centos

yum install -y postgresql10
yum install postgresql-libs python3-devel postgresql-devel
yum install gcc

以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。

相關(guān)文章

  • python 讀入多行數(shù)據(jù)的實(shí)例

    python 讀入多行數(shù)據(jù)的實(shí)例

    下面小編就為大家分享一篇python 讀入多行數(shù)據(jù)的實(shí)例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-04-04
  • Python實(shí)現(xiàn)高效求解素數(shù)代碼實(shí)例

    Python實(shí)現(xiàn)高效求解素數(shù)代碼實(shí)例

    這篇文章主要介紹了Python實(shí)現(xiàn)高效求解素數(shù)代碼實(shí)例,本文直接給出代碼實(shí)例,需要的朋友可以參考下
    2015-06-06
  • Python 實(shí)現(xiàn)二叉查找樹的示例代碼

    Python 實(shí)現(xiàn)二叉查找樹的示例代碼

    這篇文章主要介紹了Python 實(shí)現(xiàn)二叉查找樹的示例代碼,幫助大家更好的理解和使用python,感興趣的朋友可以了解下
    2020-12-12
  • Windows中使用wxPython和py2exe開發(fā)Python的GUI程序的實(shí)例教程

    Windows中使用wxPython和py2exe開發(fā)Python的GUI程序的實(shí)例教程

    wxPython是一款集成了Python的圖形化類庫的工具,而py2exe是一款將Python程序轉(zhuǎn)換為exe可執(zhí)行文件的程序,二者搭配可以輕松地在Windows中創(chuàng)建圖形化程序,這里我們就來學(xué)習(xí)Windows中使用wxPython和py2exe開發(fā)Python的GUI程序的實(shí)例教程:
    2016-07-07
  • 關(guān)于pandas的read_csv方法使用解讀

    關(guān)于pandas的read_csv方法使用解讀

    這篇文章主要介紹了關(guān)于pandas的read_csv方法使用,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2025-04-04
  • python打包生成so文件的實(shí)現(xiàn)

    python打包生成so文件的實(shí)現(xiàn)

    這篇文章主要介紹了python打包生成so文件的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-10-10
  • Python Tkinter Entry和Text的添加與使用詳解

    Python Tkinter Entry和Text的添加與使用詳解

    這篇文章主要介紹了Python Tkinter Entry和Text的添加與使用詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-03-03
  • Python opencv缺陷檢測的實(shí)現(xiàn)及問題解決

    Python opencv缺陷檢測的實(shí)現(xiàn)及問題解決

    這篇文章主要介紹了Python opencv缺陷檢測的實(shí)現(xiàn)及問題解決,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-04-04
  • python實(shí)現(xiàn)簡單銀行管理系統(tǒng)

    python實(shí)現(xiàn)簡單銀行管理系統(tǒng)

    這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)簡單銀行管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-10-10
  • Pyqt5將多個類組合在一個界面顯示的完整示例

    Pyqt5將多個類組合在一個界面顯示的完整示例

    這篇文章主要給大家介紹了關(guān)于Pyqt5將多個類組合在一個界面顯示的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2021-09-09

最新評論