2017-09-27 109 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 (扩展名)...非常感谢 –