已经过去 1 个月了,我仍然无法弄清楚我或 azure 中的应用服务出了什么问题。
我使用了 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 Pillow==4.2.1 pytz==2017.2 requests==2.18.4 urllib3==1.22
当我使用本地 Git 存储库部署到 Azure Web 服务(Python2.7、Windows)时,它似乎没有安装要求。
我尝试了wheel,但它没有做任何事情,并且通过scm powershell我无法安装任何要求,例如:
Python -m pip install django
它没有给我任何权限错误。
最佳答案
在 Azure WebApps 上,Python 默认安装在路径 D:\Python27\
它没有权限让用户执行任何写入操作,例如命令 pip install <packages>
将 Python 包安装到 libs
,除了路径 D:\home\
下.
所以首先你需要在路径 D:\home
安装一个新的 Python 运行时通过Kudu站点扩展,如下图。
然后就可以在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 代码编译器。
Troubleshooting - Package Installation
Some packages may not install using pip when run on Azure. It may simply be that the package is not available on the Python Package Index. It could be that a compiler is required (a compiler is not available on the machine running the web app in Azure App Service).
您需要从here下载packagewheel文件通过命令curl -o <wheel-file-name> <wheel-file-url>
在 Kudu CMD 上,并通过命令 python -m pip install <wheel-file-name>
安装它们.
安装完所有软件包后,您可以将 django web 应用程序上传到 D:\home\site\wwwroot
,这个路径下的文件结构看起来像官方的sample包括这些目录 app
, <your-django-project-name>
由 PTVS 在 VS 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>
希望有帮助。如有任何疑问,请随时告诉我。
关于python - 为什么 azure 应用程序服务 django 部署不断失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46440844/