Python 如何在Azure应用程序服务Windows web app上安装psycopg2?

Python 如何在Azure应用程序服务Windows web app上安装psycopg2?,python,postgresql,azure,Python,Postgresql,Azure,我正在部署Azure应用程序服务。应用程序设置为:Windows主机、32位和Python 3.4。我已经让其他一切工作,但当我试图切换到使用Postgres数据库,然后我遇到了一个问题。当pip尝试从requirements.txt安装需求时,它无法安装psycopg2。错误是: > env\scripts\pip install psycopg2 D:\home\site\wwwroot Downloading/unpacking psycopg2 Running setup.py

我正在部署Azure应用程序服务。应用程序设置为:Windows主机、32位和Python 3.4。我已经让其他一切工作,但当我试图切换到使用Postgres数据库,然后我遇到了一个问题。当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
via 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.

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

我解决这个问题的方法是将Python 3.6.1 32位作为“扩展”安装。这些扩展在Azure的web应用程序设置的左窗格中可用,并允许用户选择任何版本的Python。一旦扩展被激活,一个新的Python文件夹将在D:\home\python36中可用(例如)。从这里开始,运行
pip install psycopg2
不会出现任何问题


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

试试wheel x64包???