question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No module named azure in pyvenv

See original GitHub issue

Description

Installing azure-cli to a Python 3 venv produces invalid az command.

$ python3.6 -m venv ~/azure
$ ~/azure/bin/pip install -q azure-cli
$ ~/azure/bin/python --version        
Python 3.6.1
$ ~/azure/bin/az
/usr/local/opt/python/bin/python2.7: No module named azure

Whatever magic the az script is attempting to do is apparently not detecting the virtual environment and is instead invoking an old Python from a different environment where azure is not installed.

It’s possible this installation method isn’t supported, but as a Python engineer, I would have expected it to work.


Environment summary

Install Method: How did you install the CLI? (e.g. pip, interactive script, apt-get, Docker, MSI, nightly)
Answer here: pip

CLI Version: What version of the CLI and modules are installed? (Use az --version)
Answer here: 2.0.10

OS Version: What OS and version are you using?
Answer here: macOS 10.12.5

Shell Type: What shell are you using? (e.g. bash, cmd.exe, Bash on Windows)
Answer here: zsh

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
jaracocommented, Jul 8, 2017

Using /usr/bin/env python doesn’t work either. Replacing it with $DIR/python does work, however:

$ sed -i -e 's|python |$DIR/python |' /opt/azure-env/bin/az
$ /opt/azure-env/bin/az --version | head -n 1
azure-cli (2.0.10)
1reaction
hemakecommented, Jan 4, 2018

I have both python and python3 environments installed. Chose toinstall azure-cli to python3. Even if you have alias pointing python to python3 did not help. The command $ cat $(which az) @derekbekoe pointed out solved the issue. In my case I edit the az file as simply changing the python in the last line to python3:

#!/bin/bash

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
  DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
  SOURCE="$(readlink "$SOURCE")"
  [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"

export PYTHONPATH="${DIR}/src:${PYTHONPATH}"

python3 -m azure.cli "$@"

python3 above will automatically point to /usr/bin/python3 and solved the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python- no module named 'azure' - Stack Overflow
Recommend to use virtualenv or miniconda (Anaconda) with a specific environment for your project. You should create a requierments.txt or conda- ...
Read more >
No module named 'azure.storage.blob' - Microsoft Q&A
Im writing in VS Code and python, on a windows computer. I'm trying to create an Azure function with Blob Trigger. When I...
Read more >
No module named 'azure-storage-blob' – Finxter
Quick Fix: Python raises the ImportError: No module named 'azure-storage-blob' when it cannot find the library azure-storage-blob . The most frequent source ...
Read more >
venv — Creation of virtual environments — Python 3.11.1 ...
Source code: Lib/venv/ The venv module supports creating lightweight ... from which the command was run (a common name for the target directory...
Read more >
No module named 'azure.storage'; 'azure' is not a package ...
I have this Dockerfile: # Base Image FROM python:3.8-slim LABEL maintainer="gizelly" # Arguments that can be set with docker build ARG ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found