Sunday, September 10, 2023

Installing Azure CLI in conda virtual environment

Installing Azure CLI in conda virtual environment





Note: we aren't using yum or dnf here, we are going to using virtualenv to manage the packages.

OS version: Oracle Linux 8.8

Option 1: curl based method using install.py script
https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-linux?pivots=script

Result: Failed

Error:
(azcli) [vagrant@localhost azureinstall]$ curl -L https://aka.ms/InstallAzureCli | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  1405  100  1405    0     0   1703      0 --:--:-- --:--:-- --:--:--  4390
Downloading Azure CLI install script from https://azurecliprod.blob.core.windows.net/install.py to /tmp/azure_cli_install_tmp_zF6J3v.
######################################################################## 100.0%
...
Also creating executable in /home/vagrant/lib/azure-cli/bin/python
ERROR: The executable /home/vagrant/lib/azure-cli/bin/python3 is not functioning
ERROR: It thinks sys.prefix is '/u01/app/miniconda3/envs/azcli' (should be '/home/vagrant/lib/azure-cli')
ERROR: virtualenv is not compatible with this system or executable
Traceback (most recent call last):
  File "/tmp/azure_cli_install_tmp_zF6J3v", line 415, in <module>
    main()
  File "/tmp/azure_cli_install_tmp_zF6J3v", line 399, in main
    create_virtualenv(tmp_dir, install_dir)
  File "/tmp/azure_cli_install_tmp_zF6J3v", line 144, in create_virtualenv
    exec_command(cmd, cwd=working_dir)
  File "/tmp/azure_cli_install_tmp_zF6J3v", line 105, in exec_command
    subprocess.check_call(command_list, cwd=cwd, env=env)
  File "/u01/app/miniconda3/envs/azcli/lib/python3.11/subprocess.py", line 413, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/u01/app/miniconda3/envs/azcli/bin/python3', 'virtualenv.py', '--python', '/u01/app/miniconda3/envs/azcli/bin/python3', '/home/vagrant/lib/azure-cli']' returned non-zero exit status 100.
(azcli) [vagrant@localhost azureinstall]$


Reference to fix the issue: https://github.com/Azure/azure-cli/issues

Reading 1: https://github.com/Azure/azure-cli/issues/26590

Key callout: 
I believe you are following https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-linux?pivots=script, 
but this script is also almost "deprecated". You may use other approaches to install Azure CLI:

Use a native package manager, such as apt, dnf and tdnf: https://learn.microsoft.com/en-us/cli/azure/install-azure-cli
Manually create a virtual environment with built-in library venv and install with pip: [Doc] Add doc for installing Azure CLI with pip #20476

Option 2: Using python directly perform what install.py attempted but without virtual environment instruction

https://github.com/Azure/azure-cli/issues/20476

Steps for windows:

# Create a virtual environment
python -m venv azure-cli-env

# Update pip
azure-cli-env\Scripts\python.exe -m pip install --upgrade pip

# Install azure-cli
azure-cli-env\Scripts\python.exe -m pip install azure-cli

# Run any Azure CLI commands
azure-cli-env\Scripts\az --version


How did we do on OL8:

1) # Create a virtual environment
#python -m venv azure-cli-env  ### skipped since I already have a virtual environment with conda

2) # Update pip
#azure-cli-env\Scripts\python.exe -m pip install --upgrade pip ### I installed the latest python and dependent package using conda

3) # Install azure-cli
azure-cli-env\Scripts\python.exe -m pip install azure-cli

Actual command:
python3 -m pip install azure-cli

Actual output:

(azcli) [vagrant@localhost ~]$ python3 -m pip install azure-cli
Collecting azure-cli
  Obtaining dependency information for azure-cli from https://files.pythonhosted.org/packages/4f/45/370fe2058345d81acf7bc1a23af95888e92104adbffa1bbc9e9403b2a769/azure_cli-2.52.0-py3-none-any.whl.metadata
  Downloading azure_cli-2.52.0-py3-none-any.whl.metadata (8.3 kB)
Collecting antlr4-python3-runtime~=4.9.3 (from azure-cli)
  Downloading antlr4-python3-runtime-4.9.3.tar.gz (117 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 117.0/117.0 kB 4.7 MB/s eta 0:00:00
  Preparing metadata (setup.py) ... done
Collecting azure-appconfiguration~=1.1.1 (from azure-cli)
...
ccesscontrol-0.5.0 azure-synapse-artifacts-0.17.0 azure-synapse-managedprivateendpoints-0.4.0 azure-synapse-spark-0.2.0 bcrypt-4.0.1 certifi-2023.7.22 cffi-1.15.1 chardet-3.0.4 charset-normalizer-3.2.0 colorama-0.4.6 cryptography-41.0.3 deprecated-1.2.14 distro-1.8.0 fabric-2.7.1 humanfriendly-10.0 idna-3.4 invoke-1.7.3 isodate-0.6.1 javaproperties-0.5.2 jmespath-1.0.1 jsondiff-2.0.0 knack-0.11.0 msal-1.24.0b1 msal-extensions-1.0.0 msrest-0.7.1 msrestazure-0.6.4 oauthlib-3.2.2 packaging-23.1 paramiko-3.3.1 pathlib2-2.3.7.post1 pkginfo-1.9.6 portalocker-2.7.0 psutil-5.9.5 pycparser-2.21 pygments-2.16.1 pyopenssl-23.2.0 python-dateutil-2.8.2 pyyaml-6.0.1 requests-2.31.0 requests-oauthlib-1.3.1 scp-0.13.6 semver-2.13.0 six-1.16.0 sshtunnel-0.1.5 tabulate-0.9.0 typing-extensions-4.7.1 urllib3-2.0.4 websocket-client-1.3.3 wrapt-1.15.0 xmltodict-0.13.0
(azcli) [vagrant@localhost ~]$

4) # Run any Azure CLI commands
azure-cli-env\Scripts\az --version

Actual command:
az --version

(azcli) [vagrant@localhost ~]$ az --version
azure-cli                         2.52.0

core                              2.52.0
telemetry                          1.1.0

Dependencies:
msal                            1.24.0b1
azure-mgmt-resource             23.1.0b2

Python location '/u01/app/miniconda3/envs/azcli/bin/python3'
Extensions directory '/home/vagrant/.azure/cliextensions'

Python (Linux) 3.11.4 (main, Jul  5 2023, 13:45:01) [GCC 11.2.0]

Legal docs and information: aka.ms/AzureCliLegal


Your CLI is up-to-date.
(azcli) [vagrant@localhost ~]$

5) Where is my az command installed

(azcli) [vagrant@localhost ~]$ which az
/u01/app/miniconda3/envs/azcli/bin/az
(azcli) [vagrant@localhost ~]$

So it is properly sitting in a subdirectory under my conda env.

(azcli) [vagrant@localhost ~]$ conda deactivate
(base) [vagrant@localhost ~]$

(base) [vagrant@localhost ~]$ az --version
-bash: az: command not found
(base) [vagrant@localhost ~]$

(base) [vagrant@localhost ~]$ conda activate azcli
(azcli) [vagrant@localhost ~]$ az --version
azure-cli                         2.52.0

core                              2.52.0
telemetry                          1.1.0

Dependencies:
msal                            1.24.0b1
azure-mgmt-resource             23.1.0b2

Python location '/u01/app/miniconda3/envs/azcli/bin/python3'
Extensions directory '/home/vagrant/.azure/cliextensions'

Python (Linux) 3.11.4 (main, Jul  5 2023, 13:45:01) [GCC 11.2.0]

Legal docs and information: aka.ms/AzureCliLegal


Your CLI is up-to-date.
(azcli) [vagrant@localhost ~]$


YouTube Video: 


No comments:

Post a Comment

Flashback data archive steps

 Objective: Ways to track DML changes in a table Detailed objective: We should be able to track the changes in the table at any point in tim...