【问题标题】:How do I install psycopg2 on Azure app service Windows web app?如何在 Azure 应用服务 Windows Web 应用上安装 psycopg2?
【发布时间】:2017-07-22 17:52:52
【问题描述】:

我正在部署到 Azure 应用服务。应用程序设置为:Windows 主机、32 位和 Python 3.4。我已经完成了所有其他工作,但是当我尝试切换到使用 Postgres DB 时,我遇到了一个问题。当 pip 尝试从 requirements.txt 安装需求时,它无法安装 psycopg2。错误是:

> env\scripts\pip install psycopg2
D:\home\site\wwwroot
Downloading/unpacking psycopg2
  Running setup.py (path:D:\home\site\wwwroot\env\build\psycopg2\setup.py) egg_info for package psycopg2
    Error: pg_config executable not found. 

显然这是因为它正在尝试编译 pg 库,但我不明白为什么当 pypi 页面上列出了声称适用于 cp34-win32 的轮子时它正在尝试编译。

我尝试将轮子提交到存储库,然后在部署期间直接安装轮子(env\scripts\pip install wheelhouse\psycopg2-2.7.1-cp34-cp34m-win32.whl 通过 deploy.cmd)但这会导致此错误:

> env\scripts\pip install wheelhouse\psycopg2-2.7.1-cp34-cp34m-win32.whl
D:\home\site\wwwroot
psycopg2-2.7.1-cp34-cp34m-win32.whl is not a supported wheel on this platform.

Storing debug log for failure in D:\home\pip\pip.log


> type D:\home\pip\pip.log
D:\home\site\wwwroot
------------------------------------------------------------

D:\home\site\wwwroot\env\scripts\pip run on 07/22/17 17:47:25

psycopg2-2.7.1-cp34-cp34m-win32.whl is not a supported wheel on this platform.

Exception information:

Traceback (most recent call last):

  File "D:\home\site\wwwroot\env\lib\site-packages\pip\basecommand.py", line 122, in main

    status = self.run(options, args)

  File "D:\home\site\wwwroot\env\lib\site-packages\pip\commands\install.py", line 257, in run

    InstallRequirement.from_line(name, None))

  File "D:\home\site\wwwroot\env\lib\site-packages\pip\req.py", line 167, in from_line

    raise UnsupportedWheel("%s is not a supported wheel on this platform." % wheel.filename)

pip.exceptions.UnsupportedWheel: psycopg2-2.7.1-cp34-cp34m-win32.whl is not a supported wheel on this platform.

【问题讨论】:

  • 试试wheel x64包???

标签: python postgresql azure


【解决方案1】:

问题源于 Azure 提供的 Python 3.4 版本非常旧。可用的 pip 版本不够新,无法成功安装 psycopg2 轮。尝试运行pip install -U pip 没有任何帮助。它导致 pip 安装损坏,必须删除并重新创建 env 文件夹。

解决此问题的方法是将 Python 3.6.1 32 位安装为“扩展”。这些扩展位于 Azure 中 Web 应用设置的左侧窗格中,允许用户选择任何版本的 Python。一旦扩展被激活,一个新的 Python 文件夹在 D:\home\python36 中可用(例如)。从那里运行pip install psycopg2 没有任何问题。

唯一剩下的痛苦是我无法使用新的 Python 3.6 运行 virtualenv,因此我不得不重新调整部署脚本 (deploy.cmd) 和 web.config 以引用 D 中的 Python 可执行文件: \home\python36 而不是 D:\home\wwwroot\env\scripts。还删除了 deploy.cmd 中检测 requirements.txt 和 runtime.txt 的一堆逻辑,因为不需要样板逻辑。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-01
    • 2019-05-28
    • 1970-01-01
    • 2019-04-09
    • 1970-01-01
    • 2013-04-02
    • 1970-01-01
    • 2020-02-16
    相关资源
    最近更新 更多