包要求'psycopg2==2.9.1'不满足pycharm macos

Mic*_*cha 8 python pip psycopg2 pycharm python-3.x

经过长时间的尝试:我安装了 psycopg2==2.9.1 并 安装了 pip

我尝试将其添加到我能找到的所有解释器路径中,但仍然不断收到此消息: 错误消息

我也尝试重新启动 pycharm,使缓存无效..

当尝试使用 pycharm 安装它时,我收到此错误消息:

    Collecting psycopg2==2.9.1
  Using cached psycopg2-2.9.1.tar.gz (379 kB)
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'done'
Building wheels for collected packages: psycopg2
  Building wheel for psycopg2 (setup.py): started
  Building wheel for psycopg2 (setup.py): finished with status 'error'
  Running setup.py clean for psycopg2
Failed to build psycopg2
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/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/data_index-development/venv/bin/python' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/fj/blrljwxs22q3csr4fqw7ycmc0000gn/T/pip-install-myo1zngt/psycopg2_e9a9698f63464cb99bc5bf3655675aa2/setup.py'"'"'; __file__='"'"'/private/var/folders/fj/blrljwxs22q3csr4fqw7ycmc0000gn/T/pip-install-myo1zngt/psycopg2_e9a9698f63464cb99bc5bf3655675aa2/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/fj/blrljwxs22q3csr4fqw7ycmc0000gn/T/pip-wheel-lbvr1lzp
       cwd: /private/var/folders/fj/blrljwxs22q3csr4fqw7ycmc0000gn/T/pip-install-myo1zngt/psycopg2_e9a9698f63464cb99bc5bf3655675aa2/
  Complete output (53 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.13.0-x86_64-3.9
  creating build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
  copying lib/_json.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
  copying lib/extras.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
  copying lib/errorcodes.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
  copying lib/tz.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
  copying lib/_range.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
  copying lib/_ipaddress.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
  copying lib/__init__.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
  copying lib/extensions.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
  copying lib/errors.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
  copying lib/sql.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
  copying lib/pool.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
  warning: build_py: byte-compiling is disabled, skipping.
  
  running build_ext
  building 'psycopg2._psycopg' extension
  creating build/temp.macosx-10.13.0-x86_64-3.9
  creating build/temp.macosx-10.13.0-x86_64-3.9/psycopg
  /usr/bin/clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/MISSING/DEPS//stage/include -I/MISSING/DEPS//stage/unixodbc/include -I/MISSING/DEPS//stage/include -I/MISSING/DEPS//stage/unixodbc/include -DPSYCOPG_VERSION=2.9.1 (dt dec pq3 ext lo64) -DPSYCOPG_DEBUG=1 -DPG_VERSION_NUM=140001 -DHAVE_LO64=1 -DPSYCOPG_DEBUG=1 -I/Users/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/data_index-development/venv/include -I/Applications/QGIS.app/Contents/MacOS/include/python3.9 -I. -I/opt/homebrew/include -I/opt/homebrew/include/postgresql/server -I/opt/homebrew/Cellar/icu4c/69.1/include -I/opt/homebrew/opt/openssl@1.1/include -I/opt/homebrew/opt/readline/include -c psycopg/adapter_asis.c -o build/temp.macosx-10.13.0-x86_64-3.9/psycopg/adapter_asis.o
  In file included from psycopg/adapter_asis.c:28:
  ./psycopg/psycopg.h:35:10: error: 'Python.h' file not found with <angled> include; use "quotes" instead
  #include <Python.h>
           ^~~~~~~~~~
           "Python.h"
  ./psycopg/psycopg.h:35:10: warning: non-portable path to file '<python.h>'; specified path differs in case from file name on disk [-Wnonportable-include-path]
  #include <Python.h>
           ^~~~~~~~~~
           <python.h>
  In file included from psycopg/adapter_asis.c:28:
  In file included from ./psycopg/psycopg.h:35:
  psycopg/Python.h:31:2: error: "psycopg requires Python 3.6"
  #error "psycopg requires Python 3.6"
   ^
  psycopg/Python.h:34:10: fatal error: 'structmember.h' file not found
  #include <structmember.h>
           ^~~~~~~~~~~~~~~~
  1 warning and 3 errors generated.
  
  It appears you are missing some prerequisite to build the package from source.
  
  You may install a binary package by installing 'psycopg2-binary' from PyPI.
  If you want to install psycopg2 from source, please install the packages
  required for the build and try again.
  
  For further information please check the 'doc/src/install.rst' file (also at
  <https://www.psycopg.org/docs/install.html>).
  
  error: command '/usr/bin/clang' failed with exit code 1
  ----------------------------------------
  ERROR: Failed building wheel for psycopg2
    ERROR: Command errored out with exit status 1:
     command: '/Users/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/data_index-development/venv/bin/python' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/fj/blrljwxs22q3csr4fqw7ycmc0000gn/T/pip-install-myo1zngt/psycopg2_e9a9698f63464cb99bc5bf3655675aa2/setup.py'"'"'; __file__='"'"'/private/var/folders/fj/blrljwxs22q3csr4fqw7ycmc0000gn/T/pip-install-myo1zngt/psycopg2_e9a9698f63464cb99bc5bf3655675aa2/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/fj/blrljwxs22q3csr4fqw7ycmc0000gn/T/pip-record-fkjtibr5/install-record.txt --single-version-externally-managed --compile --install-headers '/Users/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/data_index-development/venv/include/site/python3.9/psycopg2'
         cwd: /private/var/folders/fj/blrljwxs22q3csr4fqw7ycmc0000gn/T/pip-install-myo1zngt/psycopg2_e9a9698f63464cb99bc5bf3655675aa2/
    Complete output (55 lines):
    running install
    /Users/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/data_index-development/venv/lib/python3.9/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
      warnings.warn(
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.13.0-x86_64-3.9
    creating build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
    copying lib/_json.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
    copying lib/extras.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
    copying lib/errorcodes.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
    copying lib/tz.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
    copying lib/_range.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
    copying lib/_ipaddress.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
    copying lib/__init__.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
    copying lib/extensions.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
    copying lib/errors.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
    copying lib/sql.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
    copying lib/pool.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
    warning: build_py: byte-compiling is disabled, skipping.
    
    running build_ext
    building 'psycopg2._psycopg' extension
    creating build/temp.macosx-10.13.0-x86_64-3.9
    creating build/temp.macosx-10.13.0-x86_64-3.9/psycopg
    /usr/bin/clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/MISSING/DEPS//stage/include -I/MISSING/DEPS//stage/unixodbc/include -I/MISSING/DEPS//stage/include -I/MISSING/DEPS//stage/unixodbc/include -DPSYCOPG_VERSION=2.9.1 (dt dec pq3 ext lo64) -DPSYCOPG_DEBUG=1 -DPG_VERSION_NUM=140001 -DHAVE_LO64=1 -DPSYCOPG_DEBUG=1 -I/Users/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/data_index-development/venv/include -I/Applications/QGIS.app/Contents/MacOS/include/python3.9 -I. -I/opt/homebrew/include -I/opt/homebrew/include/postgresql/server -I/opt/homebrew/Cellar/icu4c/69.1/include -I/opt/homebrew/opt/openssl@1.1/include -I/opt/homebrew/opt/readline/include -c psycopg/adapter_asis.c -o build/temp.macosx-10.13.0-x86_64-3.9/psycopg/adapter_asis.o
    In file included from psycopg/adapter_asis.c:28:
    ./psycopg/psycopg.h:35:10: error: 'Python.h' file not found with <angled> include; use "quotes" instead
    #include <Python.h>
             ^~~~~~~~~~
             "Python.h"
    ./psycopg/psycopg.h:35:10: warning: non-portable path to file '<python.h>'; specified path differs in case from file name on disk [-Wnonportable-include-path]
    #include <Python.h>
             ^~~~~~~~~~
             <python.h>
    In file included from psycopg/adapter_asis.c:28:
    In file included from ./psycopg/psycopg.h:35:
    psycopg/Python.h:31:2: error: "psycopg requires Python 3.6"
    #error "psycopg requires Python 3.6"
     ^
    psycopg/Python.h:34:10: fatal error: 'structmember.h' file not found
    #include <structmember.h>
             ^~~~~~~~~~~~~~~~
    1 warning and 3 errors generated.
    
    It appears you are missing some prerequisite to build the package from source.
    
    You may install a binary package by installing 'psycopg2-binary' from PyPI.
    If you want to install psycopg2 from source, please install the packages
    required for the build and try again.
    
    For further information please check the 'doc/src/install.rst' file (also at
    <https://www.psycopg.org/docs/install.html>).
    
    error: command '/usr/bin/clang' failed with exit code 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: '/Users//Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/data_index-development/venv/bin/python' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/fj/blrljwxs22q3csr4fqw7ycmc0000gn/T/pip-install-myo1zngt/psycopg2_e9a9698f63464cb99bc5bf3655675aa2/setup.py'"'"'; __file__='"'"'/private/var/folders/fj/blrljwxs22q3csr4fqw7ycmc0000gn/T/pip-install-myo1zngt/psycopg2_e9a9698f63464cb99bc5bf3655675aa2/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/fj/blrljwxs22q3csr4fqw7ycmc0000gn/T/pip-record-fkjtibr5/install-record.txt --single-version-externally-managed --compile --install-headers '/Users/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/data_index-development/venv/include/site/python3.9/psycopg2' Check the logs for full command output.
Run Code Online (Sandbox Code Playgroud)

有什么办法可以解决呢?

0 0*_*0 0 6

您正在尝试从源代码构建 psycopg 包。这需要 Python 的开发文件,例如Python.hmacOS 上通常不会自动提供的文件。

相反,请尝试错误消息中的建议:安装 psycopg_binary:

pip install psycopg2-binary
Run Code Online (Sandbox Code Playgroud)

安装的软件包只是 psycopg2,但不需要从源代码编译它。


War*_*kaz -2

在使用 anaconda 时,我通常会遇到类似的情况,我必须手动删除文件夹位置并重新安装才能导入(即使使用新环境)。

我建议您尝试具有相同要求的 anaconda、miniconda,看看它们是否可以帮助您解决环境问题。注意:这需要单独安装。遵循一些创建指南,但一般来说,本质是这样的:

conda create --name testenv python=3.8

conda activate testenv

conda install psycopg2"==2.9.1" -c conda-forge

在终端中执行最后一个命令后,您将得到类似的内容(只是版本不同,但已添加到 2.9.1 的命令中): 在此输入图像描述

如果你不熟悉频道和命令,一般可以在anaconda网站上搜索。

检查环境本身是否一切正常:

在 python 终端中运行 psycopg2

现在尝试在 PyCharm 中使用此环境(通过将基本解释器更改为 testenv 解释器),如果仍有问题,请包含错误消息。

这也将问题与 PyCharm 或 Pip 轮分开,并查看是否可以运行获取运行环境。