Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
266 views
in Technique[技术] by (71.8m points)

python - Why is the azure app service django deploy keep failing?

It's been 1 month and I still can't figure out what's wrong with me or app service in azure.

I used python 2.7 and django 1.11.3, with this 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

When I deploy with Local Git Repository to Azure Web Service(Python2.7, Windows) it doesn't seems to install the requirements.

I tried wheel but it doesn't do anything, and via scm powershell I failed to install any of the requirements, example:

Python -m pip install django

It gave me no permission error.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

On Azure WebApps, Python is installed default at the path D:Python27 which has no permission for users to do any write operations like command pip install <packages> to install Python packages to libs, besides under the path D:home.

So first you need to install a new Python runtime at the path D:home via Kudu site extensions, as the figure below.

enter image description here

Then, you can see the Python directory under D:home which you have the write operation permission.

enter image description here

For installing Python packages you want, do the commands as below to install pip tool.

D:home> cd Python27
D:homePython27> 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:homePython27> python get-pip.py
Requirement already up-to-date: pip in d:homepython27libsite-packages
Collecting wheel
  Downloading wheel-0.30.0-py2.py3-none-any.whl (49kB)
Installing collected packages: wheel
Successfully installed wheel-0.30.0

The next, you can install these packages via python -m pip install <package-name>, such as python -m pip install django==1.11.5 as below.

D:homePython27> 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

As the offical document said, for Troubleshooting - Package Installation, as below, like for package Pillow need compiler for C code.

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).

You need to download package wheel files from here via command curl -o <wheel-file-name> <wheel-file-url> on Kudu CMD, and install them via command python -m pip install <wheel-file-name>.

After installed all packages, you can upload your django webapp to D:homesitewwwroot, the file structure under this path looks like the offical sample that includes these directories app, <your-django-project-name> created by PTVS on VS 2017.

Finally, please configure your web.config file to make your app works.

<configuration>
  <appSettings>
    <add key="WSGI_HANDLER" value="<your-django-project-name>.wsgi.application"/>
    <add key="PYTHONPATH" value="D:homesitewwwroot"/>
    <add key="WSGI_LOG" value="D:homeLogFileswfastcgi.log"/>
  </appSettings>
  <system.webServer>
    <handlers>
      <add name="PythonHandler" path="handler.fcgi" verb="*" modules="FastCgiModule" scriptProcessor="D:homePython27python.exe|D:homePython27wfastcgi.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>

Hope it helps. Any concern, please feel free to let me know.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...