【问题标题】:How can I install psycopg2 or psycopg2-binary on cPanel hosting?如何在 cPanel 主机上安装 psycopg2 或 psycopg2-binary?
【发布时间】:2022-01-04 21:35:56
【问题描述】:

我正在尝试在我刚刚购买的新 cPanel 托管服务器上使用 PostgreSQL 设置 Python / Flask 应用程序。

我已经设置了一个 virtualenv 并设法安装了我的所有依赖项

pip install -r requirements.txt

我无法安装 psycopg2,因此一直在尝试安装 psycopg2-binary,我相信这应该可以从我在其他帖子中阅读的内容中获得。

这是输出的 sn-p:

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 '/opt/rh/devtoolset-7/root/usr/bin/gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home/seasmuyr/virtualenv/seasonwork_live/3.8/bin/python3.8_bin -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-5z014r2g/psycopg2-binary_bda4b7c8d43e4a26bf92e27771da2a93/setup.py'"'"'; __file__='"'"'/tmp/pip-install-5z014r2g/psycopg2-binary_bda4b7c8d43e4a26bf92e27771da2a93/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 /tmp/pip-record-gq6h8obk/install-record.txt --single-version-externally-managed --compile --install-headers /home/seasmuyr/virtualenv/seasonwork_live/3.8/include/site/python3.8/psycopg2-binary Check the logs for full command output.

我已通过 Namecheap 提交了一张票,但我不确定他们是否能够在此问题上提供很多支持。在解决此问题并让 psycopg2 为我的 PostgreSQL 数据库运行时,任何帮助将不胜感激。

【问题讨论】:

  • 最好的猜测是主机上的操作系统和芯片架构与psycopg2-binary 此处的任何二进制选项都不匹配,因此安装程序正在回退到从源代码构建。
  • 我认为问题在于我在从源代码构建时没有访问 gcc 的权限?
  • 也许是这样,但psycopg2-binary 的重点是您不需要编译。
  • 我认为问题主要在于我在共享服务器上没有 root。 Namecheap 支持将尝试为我安装模块,希望这能解决问题。

标签: python linux postgresql flask psycopg2


【解决方案1】:

由于我在共享主机上的权限有限,我最终没有设法让psycopg 在服务器上工作。

使用pg8000 作为驱动程序虽然对于可能遇到此线程的任何人来说都很好。

pip install pg8000

app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql+pg8000://user:password@host:port/db'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-06
    • 1970-01-01
    • 1970-01-01
    • 2021-04-06
    • 2019-07-11
    • 2012-07-19
    • 1970-01-01
    • 2020-02-16
    相关资源
    最近更新 更多