Install packages that cannot use pip in Azure App Service

Introduction

When deploying a Python application to Azure App Service, I had a hard time installing packages that needed to be compiled by wheel, so I'll leave a note: pencil2 :: notebook: For readers, an overview of Azure App Service and Git It is intended for those who know how to deploy. If you don't have the prerequisites, you can use Configure Python with Azure App Service Web Apps or Creating a web app using Django on Azure Please see the page first.

This time, the package is installed in the following environment.

--Python 3.4.1 32bit (environment provided by App Service by default)

Deployment error

When installing packages that require wheel, [Official Documentation](https://docs.microsoft.com/en-us/azure/app-service-web/web-sites-python-create-deploy-django-app # a-nametroubleshooting --- package-installationa% E3% 83% 88% E3% 83% A9% E3% 83% 96% E3% 83% AB% E3% 82% B7% E3% 83% A5% E3% 83 % BC% E3% 83% 86% E3% 82% A3% E3% 83% B3% E3% 82% B0 ---% E3% 83% 91% E3% 83% 83% E3% 82% B1% E3% 83% BC% E3% 82% B8% E3% 81% AE% E3% 82% A4% E3% 83% B3% E3% 82% B9% E3% 83% 88% E3% 83% BC% E3% 83% No matter how many times I deployed with reference to AB), the following error occurred and I was in trouble. This time we will eliminate this error.

remote:   Running setup.py install for pyodbc
remote:     building 'pyodbc' extension
remote:     error: Unable to find vcvarsall.bat
remote:     Complete output from command D:\home\site\wwwroot\env\Scripts\python.exe -c "import setuptools, tokenize;__file__='D:\\home\\site\\wwwroot\\env\\build\\pyodbc\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record D:\local\Temp\pip-okpfh2du-record\install-record.txt --single-version-externally-managed --compile --install-headers D:\home\site\wwwroot\env\include\site\python3.4:
remote:     running install
remote:
remote: running build
remote:
remote: running build_ext
remote:
remote: building 'pyodbc' extension
remote:
remote: error: Unable to find vcvarsall.bat
remote:
remote: ----------------------------------------

Local build and file renaming with wheel

Azure App Service is a sandbox environment. Therefore, you cannot install a library created by wrapping C or C ++ with ** pip **. To install those packages, you need ** pre-build with wheel **. Also, the Python environment you build must be on the same platform / architecture / version as App Service. That is, you need Python 2.7 32bit or 3.4 32bit on Windows. Also, the C ++ environment is for Python 2.7 and [Python 3](https://www.microsoft. Please note that it is different for com / ja-jp / download / details.aspx? Id = 5555). When the environment is ready, execute the following command.

python -m pip install --upgrade pip
pip install wheel
pip wheel azure-storage
pip wheel django-pyodbc-azure

When you execute the above command, a .whl file will be generated. Create a ** wheelhouse ** folder in the root directory of the application you plan to deploy and copy it there.

Then rename part of the copied .whl file. This was the biggest stumbling block, but ** App Service deployments only support the none tag **: confounded: (Github [Issue](https://github.com/Azure/azure] -storage-python / issues / 219 # issuecomment-250763151) I finally arrived ...) So, cryptography-1.5.2-cp34-cp34m-win32.whl => cryptography-1.5.2-cp34 Rename cp34m from the file name to none in the form -none-win32.whl. In the package installed this time, cryptography, cffi, and pyodbc have been renamed. Even if you install a package different from mine, please be suspicious if the .whl file does not contain none.

Modify requirements.txt

Then add --find-links wheelhouse to the beginning of requirements.txt. Now when you deploy Git, it will search for the package in the wheelhouse. In addition, requirements.txt is as follows.

--find-links wheelhouse
django==1.11
azure-storage==0.34.3
django-pyodbc-azure==1.11

After that, if you pull the changes with Git, it is the installation environment.

Finally

Azure App Service is very convenient, but you have a habit of installing packages. .. .. I got the impression that deploying an app created with C # or Node.js was much easier.

Recommended Posts

Install packages that cannot use pip in Azure App Service
[Road to intermediate Python] Install packages in bulk with pip
Install packages that need to be compiled with Python3 with pip [Windows]
Measures that pip install cannot be done with pycharm or import ssl cannot be done
In pip install clang: error: unknown argument:'-mno-fused-madd'
Install python on xserver to use pip
pipsi: use packages without polluting system pip
Manage python packages to install in containers