Azure-cli: The way to configure Azure CLI to use Python 3.5 on system where the default Python version is 2.x

Created on 16 Mar 2017  路  3Comments  路  Source: Azure/azure-cli

According to https://docs.microsoft.com/en-us/cli/azure/install-azure-cli, Microsoft recommends Python 3.5 for Azure CLI on Linux. But some applications need to be run using Python 2.x. In that case, Python 2.x and Python 3.x need to be installed side-by-side. However, We don鈥檛 know how to configure Azure CLI to use Python 3.5 on a system where the default Python version is 2.x.

Most helpful comment

I think you can use virtual environment and "-p" option.
I attached reference on Stackover flow.

http://stackoverflow.com/questions/1534210/use-different-python-version-with-virtualenv

All 3 comments

I think you can use virtual environment and "-p" option.
I attached reference on Stackover flow.

http://stackoverflow.com/questions/1534210/use-different-python-version-with-virtualenv

Typically, If you are using ubuntu or other debian distro,
you could refer to the following procedure.

installation of python virtualenv and azure-cli with py3 environment

pip install virtualenv
mkdir azure-cli-with-python3
which python3
cd azure-cli-with-python3
virtualenv -p /usr/bin/python3.5 .
source ./bin/activate
sudo apt install python3-dev
pip install azure-cli
python --version
python --version

result

Python 3.5.2

Confirmation of azure-cli version.

az --version

result

azure-cli (2.0.1)

acs (2.0.1)
appservice (0.1.1b6)
batch (0.1.1b5)
cloud (2.0.0)
component (2.0.0)
configure (2.0.1)
container (0.1.1b4)
core (2.0.1)
documentdb (0.1.1b2)
feedback (2.0.0)
find (0.0.1b1)
iot (0.1.1b3)
keyvault (0.1.1b6)
network (2.0.1)
nspkg (2.0.0)
profile (2.0.1)
redis (0.1.1b3)
resource (2.0.1)
role (2.0.0)
sql (0.1.1b6)
storage (2.0.1)
vm (2.0.1)

Python (Linux) 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609]

What @sasukeh suggested is the correct approach. You can either update your system to use Python 3 by default or create a virtual environement with Python 3 (recommended for various reasons)

Was this page helpful?
0 / 5 - 0 ratings