【问题标题】:Gcc error when installing psycopg2 into a virtualenv (Lubuntu 12.04, python 2.7)将 psycopg2 安装到 virtualenv 时出现 Gcc 错误(Lubuntu 12.04,python 2.7)
【发布时间】:2012-07-15 05:15:07
【问题描述】:

我正在尝试使用 pip 将 psycopg2 安装到 virtualenv 中,但似乎存在某种我无法理解的 gcc 错误。我已经按照其他一些问题的建议安装了 python-dev 和 libpq-dev。

pip install psycopg2
Downloading/unpacking psycopg2
  Running setup.py egg_info for package psycopg2

    no previously-included directories found matching 'doc/src/_build'
Installing collected packages: psycopg2
  Running setup.py install for psycopg2
    building 'psycopg2._psycopg' extension
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.4.5 (dt dec pq3 ext)" -DPG_VERSION_HEX=0x090104 -DPSYCOPG_EXTENSIONS=1 -DPSYCOPG_NEW_BOOLEAN=1 -DHAVE_PQFREEMEM=1 -I/usr/include/python2.7 -I. -I/usr/include/postgresql -I/usr/include/postgresql/9.1/server -c psycopg/psycopgmodule.c -o build/temp.linux-i686-2.7/psycopg/psycopgmodule.o -Wdeclaration-after-statement
    gcc: error trying to exec 'as': execvp: No such file or directory
    error: command 'gcc' failed with exit status 1
    Complete output from command /home/mdang/Dropbox/WebDev/ideas/venv/bin/python -c "import setuptools;__file__='/home/mdang/Dropbox/WebDev/ideas/venv/build/psycopg2/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-SBgH20-record/install-record.txt --install-headers /home/mdang/Dropbox/WebDev/ideas/venv/include/site/python2.7:
    running install

running build

running build_py

running build_ext

building 'psycopg2._psycopg' extension

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.4.5 (dt dec pq3 ext)" -DPG_VERSION_HEX=0x090104 -DPSYCOPG_EXTENSIONS=1 -DPSYCOPG_NEW_BOOLEAN=1 -DHAVE_PQFREEMEM=1 -I/usr/include/python2.7 -I. -I/usr/include/postgresql -I/usr/include/postgresql/9.1/server -c psycopg/psycopgmodule.c -o build/temp.linux-i686-2.7/psycopg/psycopgmodule.o -Wdeclaration-after-statement

gcc: error trying to exec 'as': execvp: No such file or directory

error: command 'gcc' failed with exit status 1

----------------------------------------
Command /home/mdang/Dropbox/WebDev/ideas/venv/bin/python -c "import setuptools;__file__='/home/mdang/Dropbox/WebDev/ideas/venv/build/psycopg2/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-SBgH20-record/install-record.txt --install-headers /home/mdang/Dropbox/WebDev/ideas/venv/include/site/python2.7 failed with error code 1 in /home/mdang/Dropbox/WebDev/ideas/venv/build/psycopg2
Storing complete log in /home/mdang/.pip/pip.log

【问题讨论】:

  • 它随 Ubuntu 一起安装。我尝试使用突触重新安装,但这并没有改变任何东西。我需要在 virtualenv 中设置 gcc 吗?

标签: python postgresql virtualenv


【解决方案1】:

编辑您的 sources.list 文件(通常在 etc/apt/sources.list 中找到)并为每个对应的 deb 行添加一个 deb-src

deb http://in.archive.ubuntu.com/ubuntu/ 精确主限制

deb-src http://in.archive.ubuntu.com/ubuntu/精确主受限#添加这一行

deb http://in.archive.ubuntu.com/ubuntu/precision-updates main 受限

deb-src http://in.archive.ubuntu.com/ubuntu/precision-updates main restricted #添加这一行

两者的区别:

  • deb:这些存储库包含二进制文件或预编译包。 大多数用户都需要这些存储库。
  • deb-src:这些存储库包含源代码 包。对开发者有用。

现在试试:

sudo apt-get update
sudo apt-get build-dep psycopg2  # The name has changed to `psycopg2` from `python-psycopg2` 

【讨论】:

    【解决方案2】:

    你需要安装两个东西:

    1. sudo apt-get install build-essential
    2. sudo apt-get build-dep python-psycopg2

    第一个安装您需要的必要构建工具,第二个安装您在 virtualenv 中编译 psycopg2 所需的依赖项。

    【讨论】:

    • 感谢您的回复。我尝试了您的解决方案,它说 build-essentials 是最新的,并且:无法找到 psycopg2 的源包。
    猜你喜欢
    • 2013-12-17
    • 2021-09-10
    • 2015-07-20
    • 2011-02-27
    • 2014-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多