简体   繁体   English

如何在 Azure Cloud Shell 中安装 python 3.6

[英]How to install python 3.6 in your Azure Cloud Shell

I am creating a serverless function with the help of python.我在 python 的帮助下创建了一个无服务器函数。 but when I try to enable it it says you have python 3.5.但是当我尝试启用它时,它说你有 python 3.5。

how do I install python 3.6 on the azure cloud shell that we access to at portal.azure.com?如何在我们在 portal.azure.com 上访问的 azure 云 shell 上安装 python 3.6?

It sounds like you want to install Python 3.6 instead of Python 3.5 on Azure Cloud Shell, as the figure below.听起来你想在 Azure Cloud Shell 上安装 Python 3.6 而不是 Python 3.5,如下图。

在此处输入图片说明

Let's first check the OS version in Azure Cloud Shell via lsb_release -a and uname -a , as the figure below.我们首先通过lsb_release -auname -a查看 Azure Cloud Shell 中的操作系统版本,如下图。

在此处输入图片说明

According to the result of the figure above, I see it's an Ubuntu 16.04 x86_64 version.根据上图的结果,我看到它是一个 Ubuntu 16.04 x86_64 版本。 And to check the filesystem information via df -a , as the figure below, I also see it's just an Ubuntu Docker image.并通过df -a检查文件系统信息,如下图,我还看到它只是一个 Ubuntu Docker 映像。

在此处输入图片说明

I tried to do the normal install operations of Ubuntu via sudo apt-get install python3.6 or apt-get install python3.6 , but failed because there is no sudo command and no root permission for the current user, as the figure below.我尝试通过sudo apt-get install python3.6apt-get install python3.6进行Ubuntu的正常安装操作,但由于没有sudo命令并且当前用户没有root权限而失败,如下图。

在此处输入图片说明

So the only workaround is to download a pre-compiled Python 3.6 release to install on it.所以唯一的解决方法是下载一个预编译的 Python 3.6 版本来安装它。 The offical Python website only releases the archive file of source codes with tar.gz suffix, not pre-compiled version for Linux, it's too complex to cost long time to compile Python source code to get a Python runtime via gcc and its library dependencies, so finally I decided to install a miniconda release of Python 3.6, which comes from https://repo.continuum.io/miniconda/ , and what I used is https://repo.continuum.io/miniconda/Miniconda3-4.5.4-Linux-x86_64.sh . Python官方网站只发布了后缀为tar.gz的源代码归档文件,不是Linux的预编译版本,编译Python源代码太复杂,需要很长时间才能通过gcc及其库依赖获得Python运行时,所以最后我决定安装 Python 3.6 的miniconda版本,它来自https://repo.continuum.io/miniconda/ ,我使用的是https://repo.continuum.io/miniconda/Miniconda3-4.5。 4-Linux-x86_64.sh

Here is my steps and screenshots.这是我的步骤和屏幕截图。

  1. Directly to download the installation shell file Miniconda3-4.5.4-Linux-x86_64.sh and install it via commands直接下载安装shell文件Miniconda3-4.5.4-Linux-x86_64.sh并通过命令安装
    wget https://repo.continuum.io/miniconda/Miniconda3-4.5.4-Linux-x86_64.sh
    and
    sh Miniconda3-4.5.4-Linux-x86_64.sh . sh Miniconda3-4.5.4-Linux-x86_64.sh

    在此处输入图片说明

  2. The default installation path is ~ that absoluted path is /home/<your username> .默认安装路径是~绝对路径是/home/<your username> You just need to configure the environment variable PATH via command你只需要通过命令配置环境变量PATH
    export PATH=~/miniconda3/bin:$PATH
    then Python 3.6 of Anaconda will works fine for you, as the figure below.那么 Anaconda 的 Python 3.6 将适用于您,如下图所示。

    在此处输入图片说明

Even you switch to PowerShell , to follow the figure below to do the operations also can use Python 3.6 of Anaconda.即使你切换到PowerShell ,按照下图进行操作也可以使用 Anaconda 的 Python 3.6。

# PowerShell on Azure Cloud Shell
cd ~
cd miniconda3/bin
./python -V

在此处输入图片说明

Create your function.创建您的函数。

Installing a site extension with an alternative Python version and configuring the handler mapping to use that installation by default..使用替代 Python 版本安装站点扩展并配置处理程序映射以默认使用该安装..

  • Go to "Platform features > All Settings > Extensions > + Add转到“平台功能>所有设置>扩展>+添加
  • Install the "Python 3.6.2 x86" extension.安装“Python 3.6.2 x86”扩展。

  • Go to "Platform features > Applications Settings转到“平台功能 > 应用程序设置

  • Add an handler mapping: extension : fastCgi processor: D:\\home\\python362x86\\python.exe arguments: D:\\home\\python362x86\\wfastcgi.py添加处理程序映射:扩展名:fastCgi 处理器:D:\\home\\python362x86\\python.exe 参数:D:\\home\\python362x86\\wfastcgi.py

Azure Function - Handler mapping to use a specific python version Azure 函数 - 使用特定 Python 版本的处理程序映射

  • Add an application setting called WEBSITE_USE_PLACEHOLDER and set its value to 0. This is necessary to work around an Azure Functions issue that causes the Python extension to stop working after the function app is unloaded.添加名为 WEBSITE_USE_PLACEHOLDER 的应用程序设置并将其值设置为 0。这是解决 Azure Functions 问题所必需的,该问题导致 Python 扩展在卸载函数应用后停止工作。

  • Save your app settings.保存您的应用设置。

Also check this thread for further reference:另请检查此线程以获取进一步参考:

https://github.com/Azure/azure-functions-host/issues/519 https://github.com/Azure/azure-functions-host/issues/519

https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-function-python https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-function-python

Hope it helps.希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM