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

安裝python依賴包psycopg2來調用postgresql的操作

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

1、先安裝psycopg2的依賴組件

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

在安裝python依賴包psycopg之前,你必須需要先安裝postgresql數據庫的相關組件:

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

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

[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依賴包,其實安裝psycopg2也可以,但是有時候執(zhí)行pip install psycopg2會報錯,而安裝psycopg2-binary(編譯后)則不會

啟動python測試

import psycopg2

補充:安裝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

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

相關文章

  • python數據化運營的重要意義

    python數據化運營的重要意義

    在本篇文章里小編給大家分享的是關于python數據化運營的重要意義,有興趣的朋友們可以學習下。
    2019-11-11
  • MacOS?Pytorch?機器學習環(huán)境搭建方法

    MacOS?Pytorch?機器學習環(huán)境搭建方法

    這篇文章主要介紹了MacOS?Pytorch?機器學習環(huán)境搭建,學習 Pytorch?,首先要搭建好環(huán)境,這里將采用?Anoconda + Pytorch + PyCharm 來一起構建 Pytorch 學習環(huán)境,需要的朋友可以參考下
    2023-02-02
  • 如何使用python寫截屏小工具

    如何使用python寫截屏小工具

    這篇文章主要介紹了如何使用python寫截屏小工具,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-09-09
  • Python函數的參數類型和使用技巧詳解

    Python函數的參數類型和使用技巧詳解

    這篇文章主要介紹了Python函數的參數類型和使用技巧詳解,函數指通過專門的代碼組織,用來實現特定功能的代碼段,具有相對的獨立性,可以被其他代碼重復調用,需要的朋友可以參考下
    2023-08-08
  • 33個Python爬蟲項目實戰(zhàn)(推薦)

    33個Python爬蟲項目實戰(zhàn)(推薦)

    這篇文章主要介紹了33個Python爬蟲項目實戰(zhàn),小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-07-07
  • python plotly繪制直方圖實例詳解

    python plotly繪制直方圖實例詳解

    這篇文章主要介紹了python plotly繪制直方圖實例詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-07-07
  • 使用Python圖像處理庫Pillow處理圖像文件的案例分析

    使用Python圖像處理庫Pillow處理圖像文件的案例分析

    本文將通過使用Python圖像處理庫Pillow,幫助大家進一步了解Python的基本概念:模塊、對象、方法和函數的使用,文中代碼講解的非常詳細,需要的朋友可以參考下
    2023-07-07
  • 如何用Python 實現全連接神經網絡(Multi-layer Perceptron)

    如何用Python 實現全連接神經網絡(Multi-layer Perceptron)

    這篇文章主要介紹了如何用Python 實現全連接神經網絡(Multi-layer Perceptron),幫助大家更好的進行機器學習,感興趣的朋友可以了解下
    2020-10-10
  • 詳解Python如何使用Falcon構建?API

    詳解Python如何使用Falcon構建?API

    Falcon?是一個Python?的?Web?框架,專注于為構建?API?提供一個極其輕量級、超全面的性能平臺,下面小編就來為大家詳細介紹一下Python如何使用Falcon構建?API吧
    2023-11-11
  • Python使用pydub實現M4A轉MP3轉換器

    Python使用pydub實現M4A轉MP3轉換器

    這篇文章主要介紹了如何使用?wxPython?創(chuàng)建一個圖形用戶界面(GUI)應用程序,能夠將?.m4a?文件轉換為?.mp3?文件,感興趣的可以了解下
    2024-11-11

最新評論