2017-09-27 186 views
0

它已經1個月,我仍然無法弄清楚什麼是我錯了或在天青蔚藍的應用服務部署的Django持續失敗

我使用Python 2.7版和Django的1.11.3應用服務,與此requirements.txt

beautifulsoup4 == 4.6.0 CERTIFI == 2017.7.27.1 chardet的== 3.0.4 Django的== 1.11.5 IDNA == 2.6 olefile == 0.44 枕頭== 4.2.1 pytz == 2017.2 請求== 2.18.4 urllib3 == 1.22

,當我與本地Git倉庫到Azure的Web服務(Python2.7,Windows)中部署它似乎並不安裝

我試過輪要求,但它不做任何事情,並通過供應鏈管理的PowerShell我沒有盡到安裝任何的要求,例如:

的Python -m PIP安裝Django

給我沒有權限錯誤

回答

0

在Azure上的WebApp,Python是在其對用戶不喜歡命令pip install <packages>任何寫操作安裝Python包libs,除了路徑D:\home\下無權路徑D:\Python27\缺省安裝。

因此,首先您需要通過Kudu站點擴展在路徑D:\home上安裝新的Python運行時,如下圖所示。

enter image description here

然後,你可以看到你有寫操作權限D:\home下Python的目錄。

enter image description here

安裝想要Python包,做如下的命令來安裝pip工具。

D:\home> cd Python27 
D:\home\Python27> curl -o get-pip.py https://bootstrap.pypa.io/get-pip.py 
    % Total % Received % Xferd Average Speed Time Time  Time Current 
           Dload Upload Total Spent Left Speed 

100 1558k 100 1558k 0  0 5069k  0 --:--:-- --:--:-- --:--:-- 6546k 
D:\home\Python27> python get-pip.py 
Requirement already up-to-date: pip in d:\home\python27\lib\site-packages 
Collecting wheel 
    Downloading wheel-0.30.0-py2.py3-none-any.whl (49kB) 
Installing collected packages: wheel 
Successfully installed wheel-0.30.0 

下,你可以通過python -m pip install <package-name>安裝這些軟件包,如python -m pip install django==1.11.5如下。

D:\home\Python27> python -m pip install django==1.11.5 
Collecting django==1.11.5 
    Downloading Django-1.11.5-py2.py3-none-any.whl (6.9MB) 
Collecting pytz (from django==1.11.5) 
    Downloading pytz-2017.2-py2.py3-none-any.whl (484kB) 
Installing collected packages: pytz, django 

作爲官方文件表示,對於Troubleshooting - Package Installation,如以下,像包Pillow需要編譯器C代碼。

疑難解答 - 程序包安裝

當運行在Azure上一些包可能無法安裝使用PIP。它可能只是該包在Python包索引中不可用。可能需要編譯器(編譯器在運行Azure App Service中的Web應用程序的計算機上不可用)。

你需要從here通過命令curl -o <wheel-file-name> <wheel-file-url>上捻CMD下載包輪文件,並通過命令python -m pip install <wheel-file-name>安裝它們。

安裝了所有的包後,你可以上傳你的Django的web應用到D:\home\site\wwwroot,此路徑下的文件結構看起來像是官方sample包括這些目錄app<your-django-project-name>上創建VS通過PTVS 2017年

最後,請配置您的web.config文件以使您的應用程序有效。

<configuration> 
    <appSettings> 
    <add key="WSGI_HANDLER" value="<your-django-project-name>.wsgi.application"/> 
    <add key="PYTHONPATH" value="D:\home\site\wwwroot"/> 
    <add key="WSGI_LOG" value="D:\home\LogFiles\wfastcgi.log"/> 
    </appSettings> 
    <system.webServer> 
    <handlers> 
     <add name="PythonHandler" path="handler.fcgi" verb="*" modules="FastCgiModule" scriptProcessor="D:\home\Python27\python.exe|D:\home\Python27\wfastcgi.py" resourceType="Unspecified" requireAccess="Script"/> 
    </handlers> 
    <rewrite> 
     <rules> 
     <rule name="Static Files" stopProcessing="true"> 
      <conditions> 
      <add input="true" pattern="false" /> 
      </conditions> 
     </rule> 
     <rule name="Configure Python" stopProcessing="true"> 
      <match url="(.*)" ignoreCase="false" /> 
      <conditions> 
      <add input="{REQUEST_URI}" pattern="^/static/.*" ignoreCase="true" negate="true" /> 
      </conditions> 
      <action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="true" /> 
     </rule> 
     </rules> 
    </rewrite> 
    </system.webServer> 
</configuration> 

希望它有幫助。任何問題,請隨時讓我知道。

+0

嘿,現在我得到了「頁面無法顯示,因爲發生了內部服務器錯誤。」,在部署 –

+0

@HariAnugrah時看起來沒有錯誤請查看日誌路徑D:\ home \ LogFiles \ wfastcgi.log '並更新你的帖子關於這個問題。 –

+0

謝謝,我解決了問題 問題是,azure應用服務默認使用virtualenv,所以requirements.txt包自動安裝到virtualenv的python中...所以我只需編輯deploy.cmd來安裝需求到python (擴展名)...非常感謝 –