2017-07-22 86 views
1

我正在部署到Azure應用程序服務。應用程序設置爲:Windows主機,32位和Python 3.4。我還有其他所有工作,但是當我嘗試切換到使用Postgres DB時,我遇到了一個問題。當pip嘗試從requirements.txt安裝需求時,它無法安裝psycopg2。錯誤是:如何在Azure應用服務Windows Web應用上安裝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的。

我試圖犯輪庫,然後直接安裝(通過deploy.cmd env\scripts\pip install wheelhouse\psycopg2-2.7.1-cp34-cp34m-win32.whl)部署在輪但這會導致這個錯誤:

> 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. 
+0

試輪x64包??? – 4c74356b41

回答

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的一堆邏輯,因爲該樣板邏輯不是必需的。

相關問題