在 macOS 10.15 上安装 Python 3.7 的 psycopg2 出错。

10

我尝试执行pip3 install psycopg2

但是出现了以下错误,我不知道该怎么做。

请帮忙解决。

Collecting psycopg2==2.7.3.1   Using cached https://files.pythonhosted.org/packages/6b/fb/15c687eda2f925f0ff59373063fdb408471b4284714a7761daaa65c01f15/psycopg2-2.7.3.1.tar.gz Installing collected packages: psycopg2
    Running setup.py install for psycopg2: started
    Running setup.py install for psycopg2: finished with status 'error'

    ERROR: Command errored out with exit status 1:
     command: /Users/amolchakane/Desktop/Projects/kisanoauth/venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/c7/wshj0hq9637_ddn00y_52y7c0000gp/T/pycharm-packaging/psycopg2/setup.py'"'"';
__file__='"'"'/private/var/folders/c7/wshj0hq9637_ddn00y_52y7c0000gp/T/pycharm-packaging/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/c7/wshj0hq9637_ddn00y_52y7c0000gp/T/pip-record-f050z4mz/install-record.txt
--single-version-externally-managed --compile --install-headers /Users/amolchakane/Desktop/Projects/kisanoauth/venv/include/site/python3.7/psycopg2
         cwd: /private/var/folders/c7/wshj0hq9637_ddn00y_52y7c0000gp/T/pycharm-packaging/psycopg2/
    Complete output (61 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.9-x86_64-3.7
    creating build/lib.macosx-10.9-x86_64-3.7/psycopg2
    copying lib/_json.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2
    copying lib/extras.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2
    copying lib/errorcodes.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2
    copying lib/tz.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2
    copying lib/_range.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2
    copying lib/_ipaddress.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2
    copying lib/__init__.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2
    copying lib/psycopg1.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2
    copying lib/extensions.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2
    copying lib/sql.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2
    copying lib/pool.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2
    creating build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    copying tests/test_transaction.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    copying tests/dbapi20.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    copying tests/test_extras_dictcursor.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    copying tests/test_with.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    copying tests/test_types_basic.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    copying tests/test_bug_gc.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    copying tests/test_module.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    copying tests/test_psycopg2_dbapi20.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    copying tests/test_async.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    copying tests/test_dates.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    copying tests/test_async_keyword.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    copying tests/testutils.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    copying tests/test_connection.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    copying tests/test_copy.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    copying tests/test_bugX000.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    copying tests/__init__.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    copying tests/test_cursor.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    copying tests/test_types_extras.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    copying tests/test_sql.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    copying tests/test_fast_executemany.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    copying tests/test_green.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    copying tests/test_ipaddress.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    copying tests/test_cancel.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    copying tests/test_quote.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    copying tests/testconfig.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    copying tests/test_errcodes.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    copying tests/test_replication.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    copying tests/test_lobject.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    copying tests/test_notify.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    copying tests/dbapi20_tpc.py -> build/lib.macosx-10.9-x86_64-3.7/psycopg2/tests
    Skipping optional fixer: buffer
    Skipping optional fixer: idioms
    Skipping optional fixer: set_literal
    Skipping optional fixer: ws_comma
    warning: build_py: byte-compiling is disabled, skipping.

    running build_ext
    building 'psycopg2._psycopg' extension
    creating build/temp.macosx-10.9-x86_64-3.7
    creating build/temp.macosx-10.9-x86_64-3.7/psycopg
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.7.3.1 (dt dec pq3 ext lo64)" -DPG_VERSION_NUM=110500 -DHAVE_LO64=1
-I/Users/amolchakane/Desktop/Projects/kisanoauth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.5_1/include -I/usr/local/Cellar/postgresql/11.5_1/include/server -c psycopg/psycopgmodule.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/psycopgmodule.o
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    error: command 'gcc' failed with exit status 1
    ---------------------------------------- ERROR: Command errored out with exit status 1: /Users/amolchakane/Desktop/Projects/kisanoauth/venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/c7/wshj0hq9637_ddn00y_52y7c0000gp/T/pycharm-packaging/psycopg2/setup.py'"'"';
__file__='"'"'/private/var/folders/c7/wshj0hq9637_ddn00y_52y7c0000gp/T/pycharm-packaging/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/c7/wshj0hq9637_ddn00y_52y7c0000gp/T/pip-record-f050z4mz/install-record.txt
--single-version-externally-managed --compile --install-headers /Users/amolchakane/Desktop/Projects/kisanoauth/venv/include/site/python3.7/psycopg2 Check the logs for full command output.

@HimanshuPoddar 这个项目使用 django 框架,需要 psycopg2 作为依赖。因此我已经添加了 django 标签。 同时我已经正确格式化了错误信息。现在可以帮忙吗? - Amol Chakane
这个对我在Mac OSX 10.15.5上解决了问题。https://dev59.com/PFkS5IYBdhLWcg3wgW8Q#57621735 - Arnav Choudhury
2个回答

8

我可以通过安装上面评论中指示的二进制库来解决这个问题。(只是有一个拼写错误)

pip install psycopg2-binary

Amol Chakane提到的错误是指由于拼写错误而找不到软件包而引起的PIP错误。

还要确保您的pip命令引用了正确的Python版本。 在我的情况下,我正在使用一个带有Python 3的环境,因此不需要指定pip3,只需使用pip即可。


谢谢你的帮助。 - analyst_47

2
如果你是新手(就像我一样)学习Django,你可能想尝试使用psycopg2-binary代替。它适用于开发人员和测试,但不适用于生产环境。我在Mac OS Mojave上的虚拟环境中使用相同版本的Python(3.7),Django版本为2.2.6。我也无法在我的系统上安装pyscopg2。

pip install pyscopg2-binary

这些是我用来帮助自己解决问题的文档:http://initd.org/psycopg/docs/install.html#install-from-source https://pypi.org/project/psycopg2-binary/


我已经尝试过了,但是它给了我一个错误。 Amols-Air:〜amolchakane$ pip install pyscopg2-binary ERROR: Could not find a version that satisfies the requirement pyscopg2-binary (from versions: none) ERROR: No matching distribution found for pyscopg2-binary 而且我希望它也能用于生产。 - Amol Chakane
似乎xcrun和gcc错误很重要。@Housemd在这里使用了相同类型的xcrun和gcc错误修复了自己的解决方案:https://apple.stackexchange.com/questions/254380/why-am-i-getting-an-invalid-active-developer-path-when-attempting-to-use-git-a - codegrrl

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接