为什么azure应用服务Django deploy总是失败?

2024-04-24 21:28:43 发布

您现在位置:Python中文网/ 问答频道 /正文

已经一个月了,我还是不知道我和azure的应用服务出了什么问题。在

我使用了python2.7和django 1.11.3要求.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存储库部署到azureweb服务(Python2.7,Windows)时,它似乎没有安装需求。在

我试过wheel,但它什么也做不了,通过scm powershell,我无法安装任何需求,例如:

Python -m pip install django

它没有给我许可错误。在


Tags: djangogittxtazurerequestsbeautifulsoup4urllib3应用服务
1条回答
网友
1楼 · 发布于 2024-04-24 21:28:43

在Azure WebApps上,Python默认安装在路径D:\Python27\上,除了路径D:\home\下,用户没有权限执行任何写操作,比如命令pip install <packages>将Python包安装到libs。在

因此,首先需要通过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,如下所示。在

^{pr2}$

正如官方文档所说,对于^{},如下所示,对于包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).

您需要通过Kudu CMD上的命令curl -o <wheel-file-name> <wheel-file-url>here下载包轮子文件,并通过命令python -m pip install <wheel-file-name>安装它们。在

安装完所有软件包后,您可以将django webapp上载到D:\home\site\wwwroot,此路径下的文件结构类似于官方的sample,其中包含这些目录{},<your-django-project-name>,由vs2017上的PTVS创建。在

最后,请配置您的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>

希望有帮助。有任何问题,请随时告诉我。在

相关问题 更多 >