在Azure上的WebApp,Python是在其对用户不喜欢命令pip install <packages>
任何写操作安装Python包libs
,除了路径D:\home\
下无权路径D:\Python27\
缺省安装。
因此,首先您需要通过Kudu站点扩展在路径D:\home
上安装新的Python运行时,如下图所示。
然后,你可以看到你有写操作权限D:\home
下Python的目录。
安装想要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>
希望它有帮助。任何问题,请随时让我知道。
嘿,现在我得到了“页面无法显示,因为发生了内部服务器错误。”,在部署 –
@HariAnugrah时看起来没有错误请查看日志路径D:\ home \ LogFiles \ wfastcgi.log '并更新你的帖子关于这个问题。 –
谢谢,我解决了问题 问题是,azure应用服务默认使用virtualenv,所以requirements.txt包自动安装到virtualenv的python中...所以我只需编辑deploy.cmd来安装需求到python (扩展名)...非常感谢 –