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).
In this section, we'll look at ways to deal with this issue.
If the package installation requires a compiler, you should try contacting the package owner to request that wheels be made available for the package.
With the recent availability of Microsoft Visual C++ Compiler for Python 2.7, it is now easier to build packages that have native code for Python 2.7.
Note: When using this option, make sure to compile the package using a Python environment that matches the platform/architecture/version that is used on the web app in Azure App Service (Windows/32-bit/2.7 or 3.4).
If the package doesn't install because it requires a compiler, you can install the compiler on your local machine and build a wheel for the package, which you will then include in your repository.
Mac/Linux Users: If you don't have access to a Windows machine, see Create a Virtual Machine Running Windows for how to create a VM on Azure. You can use it to build the wheels, add them to the repository, and discard the VM if you like.
For Python 2.7, you can install Microsoft Visual C++ Compiler for Python 2.7.
For Python 3.4, you can install Microsoft Visual C++ 2010 Express.
To build wheels, you'll need the wheel package:
env\scripts\pip install wheel
You'll use pip wheel
to compile a dependency:
env\scripts\pip wheel azure==0.8.4
This creates a .whl file in the \wheelhouse folder. Add the \wheelhouse folder and wheel files to your repository.
Edit your requirements.txt to add the --find-links
option at the top. This tells pip to look for an exact match in the local folder before going to the python package index.
--find-links wheelhouse
azure==0.8.4
If you want to include all your dependencies in the \wheelhouse folder and not use the python package index at all, you can force pip to ignore the package index by adding --no-index
to the top of your requirements.txt.
--no-index
You can customize the deployment script to install a package in the virtual environment using an alternate installer, such as easy_install. See deploy.cmd for an example that is commented out. Make sure that such packages aren't listed in requirements.txt, to prevent pip from installing them.
Add this to the deployment script:
env\scripts\easy_install somepackage
You may also be able to use easy_install to install from an exe installer (some are zip compatible, so easy_install supports them). Add the installer to your repository, and invoke easy_install by passing the path to the executable.
Add this to the deployment script:
env\scripts\easy_install "%DEPLOYMENT_SOURCE%\installers\somepackage.exe"
Note: When using this option, make sure to use a virtual environment that matches the platform/architecture/version that is used on the web app in Azure App Service (Windows/32-bit/2.7 or 3.4).
If you include the virtual environment in the repository, you can prevent the deployment script from doing virtual environment management on Azure by creating an empty file:
.skipPythonDeployment
We recommend that you delete the existing virtual environment on the app, to prevent leftover files from when the virtual environment was managed automatically.