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.
Then, you can see the Python directory under D:home
which you have the write operation permission.
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.