Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to use azure SDK in Python

Tags:

python

azure

I did this:

sudo pip install azure azure-storage azure-servicebus azure-mgmt azure-servicemanagement-legacy

from azure import * 

Traceback (most recent call last): File "", line 1, in ImportError: No module named azure

from azure.storage import BlobService

Traceback (most recent call last): File "", line 1, in ImportError: No module named azure.storage

like image 831
Bob Avatar asked Sep 15 '25 20:09

Bob


2 Answers

Python package installed thru cmd sudo pip install exists at the paths /usr/lib/python2.7, /usr/local/python2.7, etc and their sub-folder dist-packages.

You can code import sys and print sys.path in the Python Interpreter to show the completed path list for current python environment.

Iif you installed successfully some packages like azure & azure-storage, you can find these files relate to the package in the python library paths.

However, you got the error in Import Error: No module named <package-name> when you run the code import <package-name> or from <package-name> import <class or object name>. There are two scenes that would be cause the issue normally.

  1. Package not installed successfully.
  2. The library path included package that not exists in Python system environment path sys.path in python or PYTHONHOME in environment variables.

So I think you can try to solve the issue thru three ways below.

  1. Dynamically add the package path into sys.path thru the method sys.path.append('<package path>') in python code.
  2. Check the environment variable PYTHONHOME whether or not set up. If set up PYTHONHOME, python will add package path based on PYTHONHOME into sys.path.
  3. If your python environment encounter some unknown fault that is unrecoverable, you can try to reinstall Python thru commands sudo apt-get remove python python-pip, sudo apt-get update, sudo apt-get install python python-pip on Ubuntu. It's a simple way.
like image 51
Peter Pan Avatar answered Sep 18 '25 16:09

Peter Pan


BlobService belongs to azure.storage.blob rather than the azure.storage

it should rather be

from azure.storage.blob import BlobService

Link - https://azure.microsoft.com/en-us/documentation/articles/storage-python-how-to-use-blob-storage/

If it still doesn't work for you, you might would like to use virtualEnv and do the pip install again while in virtualenv

http://docs.python-guide.org/en/latest/dev/virtualenvs/

like image 45
Brij Raj Singh - MSFT Avatar answered Sep 18 '25 16:09

Brij Raj Singh - MSFT