天天看點

Ubuntu 18.04 安裝 psycopg2 報錯

常見問題,記錄一下

pip3 install psycopg2
           
Collecting psycopg2==2.8.3 (from -r requirements.txt (line 8))
  Using cached https://files.pythonhosted.org/packages/5c/1c/6997288da181277a0c29bc39a5f9143ff20b8c99f2a7d059cfb55163e165/psycopg2-2.8.3.tar.gz
    ERROR: Command errored out with exit status 1:
     command: /home/huzing2524/.virtualenvs/circuit_board/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-ufsmqwic/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-ufsmqwic/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 pip-egg-info
         cwd: /tmp/pip-install-ufsmqwic/psycopg2/
    Complete output (7 lines):
    running egg_info
    creating pip-egg-info/psycopg2.egg-info
    writing pip-egg-info/psycopg2.egg-info/PKG-INFO
    writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt
    writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt
    writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt'
    Error: b'You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.\n'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
           
  • 解決辦法:在全局安裝依賴
  • 解釋:The

    libpq-dev

    library is built following

    Debian's libpq-dev package

    _

    idea: it contains a minimal set of

    PostgreSQL

    _ binaries and headers requried

    for building 3rd-party applications for

    PostgreSQL

    _.
    sudo apt install libpq-dev
               
    正在讀取軟體包清單... 完成
    正在分析軟體包的依賴關系樹       
    正在讀取狀态資訊... 完成       
    下列軟體包是自動安裝的并且現在不需要了:
      linux-headers-5.0.0-23 linux-headers-5.0.0-23-generic linux-image-5.0.0-23-generic linux-modules-5.0.0-23-generic linux-modules-extra-5.0.0-23-generic
    使用'sudo apt autoremove'來解除安裝它(它們)。
    建議安裝:
      postgresql-doc-10
    下列【新】軟體包将被安裝:
      libpq-dev
    更新了 0 個軟體包,新安裝了 1 個軟體包,要解除安裝 0 個軟體包,有 39 個軟體包未被更新。
    需要下載下傳 218 kB 的歸檔。
    解壓縮後會消耗 1,092 kB 的額外空間。
    擷取:1 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libpq-dev amd64 10.10-0ubuntu0.18.04.1 [218 kB]
    已下載下傳 218 kB,耗時 2秒 (95.0 kB/s)                   
    正在選中未選擇的軟體包 libpq-dev。
    (正在讀取資料庫 ... 系統目前共安裝有 207162 個檔案和目錄。)
    正準備解包 .../libpq-dev_10.10-0ubuntu0.18.04.1_amd64.deb  ...
    正在解包 libpq-dev (10.10-0ubuntu0.18.04.1) ...
    正在設定 libpq-dev (10.10-0ubuntu0.18.04.1) ...
    正在處理用于 man-db (2.8.3-2ubuntu0.1) 的觸發器 ...
               
    Collecting psycopg2==2.8.3 (from -r requirements.txt (line 8))
      Using cached https://files.pythonhosted.org/packages/5c/1c/6997288da181277a0c29bc39a5f9143ff20b8c99f2a7d059cfb55163e165/psycopg2-2.8.3.tar.gz
    Building wheels for collected packages: psycopg2
      Building wheel for psycopg2 (setup.py) ... done
      Created wheel for psycopg2: filename=psycopg2-2.8.3-cp36-cp36m-linux_x86_64.whl size=418320 sha256=4b87f24e17156d65c4276f02a01506c3301b7832b28094367c5e85baddf08c2d
      Stored in directory: /home/huzing2524/.cache/pip/wheels/48/06/67/475967017d99b988421b87bf7ee5fad0dad789dc349561786b
    Successfully built psycopg2
    Installing collected packages: psycopg2
    Successfully installed psycopg2-2.8.3