【问题标题】:error : command 'gcc' failed with exit status 1 while installing pygresql错误:安装 pygresql 时命令“gcc”失败,退出状态为 1
【发布时间】:2017-07-01 01:04:28
【问题描述】:

我正在尝试使用“pip install pygresql”安装 pygresql 包,但出现错误:命令 'gcc' failed with exit status 1 我已经尝试了很多东西,但我仍然不明白为什么它不起作用

Collecting pygresql
  Using cached PyGreSQL-5.0.3.tar.gz
Building wheels for collected packages: pygresql
  Running setup.py bdist_wheel for pygresql ... error
  Complete output from command /Users/paulinelanquetin/anaconda/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/y9/vbfql6394h3g6_4ldhwqzx1c0000gp/T/pip-build-s7kjrkvj/pygresql/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /var/folders/y9/vbfql6394h3g6_4ldhwqzx1c0000gp/T/tmpvvbd5puepip-wheel- --python-tag cp36:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.7-x86_64-3.6
  copying pg.py -> build/lib.macosx-10.7-x86_64-3.6
  copying pgdb.py -> build/lib.macosx-10.7-x86_64-3.6
  running build_ext
  building '_pg' extension
  creating build/temp.macosx-10.7-x86_64-3.6
  gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/paulinelanquetin/anaconda/include -arch x86_64 -I/Users/paulinelanquetin/anaconda/include -arch x86_64 -DPYGRESQL_VERSION=5.0.3 -DDIRECT_ACCESS -DLARGE_OBJECTS -DDEFAULT_VARS -DESCAPING_FUNCS -I/Users/paulinelanquetin/anaconda/include/python3.6m -I/usr/local/Cellar/postgresql/9.6.2/include -I/Users/paulinelanquetin/anaconda/include/python3.6m -c pgmodule.c -o build/temp.macosx-10.7-x86_64-3.6/pgmodule.o -O2 -funsigned-char -Wall -Werror
  pgmodule.c:3694:3: error: code will never be executed [-Werror,-Wunreachable-code]
                  long    num_rows;
                  ^~~~~~~~~~~~~~~~~
  1 error generated.
  error: command 'gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for pygresql
  Running setup.py clean for pygresql
Failed to build pygresql
Installing collected packages: pygresql
  Running setup.py install for pygresql ... error
    Complete output from command /Users/paulinelanquetin/anaconda/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/y9/vbfql6394h3g6_4ldhwqzx1c0000gp/T/pip-build-s7kjrkvj/pygresql/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /var/folders/y9/vbfql6394h3g6_4ldhwqzx1c0000gp/T/pip-l99qu955-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.7-x86_64-3.6
    copying pg.py -> build/lib.macosx-10.7-x86_64-3.6
    copying pgdb.py -> build/lib.macosx-10.7-x86_64-3.6
    running build_ext
    building '_pg' extension
    creating build/temp.macosx-10.7-x86_64-3.6
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/paulinelanquetin/anaconda/include -arch x86_64 -I/Users/paulinelanquetin/anaconda/include -arch x86_64 -DPYGRESQL_VERSION=5.0.3 -DDIRECT_ACCESS -DLARGE_OBJECTS -DDEFAULT_VARS -DESCAPING_FUNCS -I/Users/paulinelanquetin/anaconda/include/python3.6m -I/usr/local/Cellar/postgresql/9.6.2/include -I/Users/paulinelanquetin/anaconda/include/python3.6m -c pgmodule.c -o build/temp.macosx-10.7-x86_64-3.6/pgmodule.o -O2 -funsigned-char -Wall -Werror
    pgmodule.c:3694:3: error: code will never be executed [-Werror,-Wunreachable-code]
                    long    num_rows;
                    ^~~~~~~~~~~~~~~~~
    1 error generated.
    error: command 'gcc' failed with exit status 1

    ----------------------------------------
Command "/Users/paulinelanquetin/anaconda/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/y9/vbfql6394h3g6_4ldhwqzx1c0000gp/T/pip-build-s7kjrkvj/pygresql/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /var/folders/y9/vbfql6394h3g6_4ldhwqzx1c0000gp/T/pip-l99qu955-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/y9/vbfql6394h3g6_4ldhwqzx1c0000gp/T/pip-build-s7kjrkvj/pygresql/

【问题讨论】:

    标签: macos python-3.x pygresql


    【解决方案1】:

    对于这个问题,我找到了两个解决方案。我在尝试将 pygresql 安装到 OSX Sierra 10.12.5 上的 conda 虚拟环境中并从 xcode-select --install 安装 gcc 时遇到了这个确切的问题。我的解决方案(如果其他人发现这个)是在终端中使用这个命令:

    conda install gcc
    

    这解决了安装到 conda 环境中的问题,您可以将其用作解决方法。安装 anacondaminiconda 然后在终端中运行这些命令:

    conda create -y python=3 --name my_env
    source activate my_env
    conda install -y gcc
    pip install pygresql
    

    我强烈建议在 python 中进行开发时使用 conda 或 virtualenv 以避免此类问题。

    我在this similar issue 中找到了更直接的解决您问题的方法。通过在终端中运行这些命令,我​​能够解决 pip 直接安装到 OSX python(而不是 conda env)的问题:

    export CFLAGS="-Wno-error"
    pip install PyGreSQL
    

    【讨论】:

    • 请注意,PyGreSQL 中的 has been fixed >= 5.0.4。
    • 这里的“-y”开关有什么作用?
    猜你喜欢
    • 2012-06-21
    • 2019-12-01
    • 2023-03-19
    • 1970-01-01
    • 2014-07-06
    • 2011-11-11
    • 1970-01-01
    • 1970-01-01
    • 2016-11-01
    相关资源
    最近更新 更多