【问题标题】:How can I install psycops2 in my virtual env? [duplicate]如何在我的 virtualenv 中安装 psycopg2? [复制]
【发布时间】:2020-09-26 12:31:15
【问题描述】:

我需要安装 psycopg2 来连接 postgresql 和 django。我试过这个命令。

pip install psycopg2

但是显示了这条消息:

 Error: pg_config executable not found.

    pg_config is required to build psycopg2 from source.  Please add the directory
    containing pg_config to the $PATH or specify the full executable path with the
    option:

        python setup.py build_ext --pg-config /path/to/pg_config build ...

    or with the pg_config option in 'setup.cfg'.

    If you prefer to avoid building psycopg2 from source, please install the PyPI
    'psycopg2-binary' package instead.

    For further information please check the 'doc/src/install.rst' file (also at
    <https://www.psycopg.org/docs/install.html>).


    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\Rafid\AppData\Local\Temp\pip-install-oknhhl43\psycopg2\

我是网络开发的新手,所以详细的解决方案会很有帮助...提前致谢

【问题讨论】:

  • 这能回答你的问题吗? pg_config executable not found
  • 使用 Parvathirajan Natarajan 的回答,因为错误消息指出:“如果您不想从源代码构建 psycopg2,请改为安装 PyPI 'psycopg2-binary' 包。”

标签: python django postgresql web web-applications


【解决方案1】:

安装预编译的二进制文件,然后安装psycopg2

pip install psycopg2-binary

【讨论】:

    【解决方案2】:

    psycopg2 的安装失败,因为它无法找到它运行以查找本地 PostgreSQL 安装的配置详细信息的 PostgreSQL 可执行文件。

    有两种选择:

    1. 下载并安装 PostgreSQL,确保它在 PATH 上,然后重新运行 pip install psycopg2

      您可以从download page 获取适用于 Windows 的 PostgreSQL 安装程序。

    2. 改为运行pip install psycopg2-binary


    请注意,Psycopg2 installation instructions 声明 PostgreSQL 是先决条件。

    但是,它进一步解释了 pg_config 仅在构建时需要。

    【讨论】:

      猜你喜欢
      • 2015-07-20
      • 1970-01-01
      • 2011-03-03
      • 1970-01-01
      • 2015-01-27
      • 1970-01-01
      • 2016-02-06
      • 1970-01-01
      • 2021-01-28
      相关资源
      最近更新 更多