Using PIP in a Azure WebApp

2019-04-26 18:32发布

I'm pretty new to Azure and I'm trying to get a Django WebApp up and running. I uploaded the files using FTP, But Azure doesn't run my requirements.txt.

So I searched for a bit and found out that you can install the requirements.txtwith pip.

Back in Azure, PIP doesn't seem to work. Neither in the Console, The KUDU CMD or the KUDU powershell. Python does work.
When I try to install PIP via Python, it first says that a older version is already installed. When Python tries to upgrade PIP, it doesn't have access to the folder that it needs to edit.

I was wondering how I could use PIP in azure.
(If you know a seperate way to install the requirements.txt please tell, because this was how I originally came to this point.)

5条回答
叼着烟拽天下
2楼-- · 2019-04-26 19:05

You won't be able to upgrade the pip of your Django webapp because you will not have access to system files.

Instead you can upgrade pip of your virtualenv, which you can do by adding a line in deploy.cmd file before install requirements.txt command.

env\scripts\python -m pip install --upgrade pip

Remember not to upgrade pip with pip (env/scripts/pip) else it will uninstall global pip.

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-04-26 19:06

You can use pip by changing the path in console to Python27/Scripts

cd D:\Python27\Scripts
查看更多
【Aperson】
4楼-- · 2019-04-26 19:09

I suggest you to use Visual Studio 2013/2015 to manage your Django Project. You can get a Visual Studio 2015 Community which is free, and install PTVS 2.2 for it.

With PTVS, you can create a virtual environment with your requirement.txt, and deploy your project with Visual Studio. Sometimes, you just cannot install some Python packages due to a compiler issue (some packages specifically need a lower version of compiler). Hence, it's better you compile them in your machine and deploy the virtual environment to Azure Website.

See more detail on Django and SQL Database on Azure with Python Tools 2.2 for Visual Studio

查看更多
5楼-- · 2019-04-26 19:16

Have you tried upgrading pip with easy_install? The following worked for me in Azure kudu console:

python -m easy_install --upgrade --user pip

查看更多
Anthone
6楼-- · 2019-04-26 19:20

Based on my understanding, I think you want to create a virtual environment for Python and do some package installation using requirement.txt for a Django WebApp and got some issue.

For Django on Azure WebApp, I recommend creating a WebApp preinstalled Django from gallery on Azure old portal.

However, arccording to the Azure offical document, you also can't install some packages by using pip, please see these cases below.

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

But you can refer to the offical troubleshooting doc to deal with this issue, please see https://azure.microsoft.com/en-us/documentation/articles/web-sites-python-create-deploy-django-app/#troubleshooting---package-installation.

查看更多
登录 后发表回答