4

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

2
  • Which platform and python version you're using? Commented Dec 11, 2015 at 4:55
  • I tried with both Ubuntu 14 and OSX Commented Dec 11, 2015 at 10:17

4 Answers 4

1

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.
Sign up to request clarification or add additional context in comments.

1 Comment

this will work - but isn't the best way - OP is trying to use deprecated meta packages in this case
1

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/

2 Comments

ImportError: cannot import name BlobService
didi you PIP install finished without errors, I just tested this works really fine, or you can use virtualenv create a diff folder and do a pip install in it - fresh
1

I had very similar issue. There was a lot of confusion between python2 and python3 package versions as there was no virtual env used and I also had to ungrade pip to 18.

But anyway, this is is how I resolved the part in question.

Locate where the package was installed:

pip show azure 

The output will show the location of the package in the Location section:

Name: azure Version: 4.0.0 Summary: Microsoft Azure Client Libraries for Python Home-page: https://github.com/Azure/azure-sdk-for-python Author: Microsoft Corporation Author-email: [email protected] License: MIT License Location: /usr/local/lib/python3.6/dist-packages Requires: azure-servicefabric, azure-cosmosdb-table, azure-datalake-store, azure-loganalytics, azure-eventgrid, azure-servicemanagement-legacy, azure-servicebus, azure-graphrbac, azure-storage-blob, azure-mgmt, azure-storage-file, azure-batch, azure-applicationinsights, azure-keyvault, azure-storage-queue Required-by: 

If you do:

python -c "import sys;print(sys.path)" 

You will see a list of pip package locations:

['/app', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/dist-packages', '/usr/lib/python3/dist-packages'] 

At the begining of my python file I added:

sys.path.insert( 0, '/usr/local/lib/python3.6/dist-packages' ) 

This will make sure this package location will be checked in the first place.

UPDATE

Thinking about it in the morning, things opened from a new perspective for me. I saw, that I had #!/usr/bin/python at the beginning of my python file, which says to use the wrong interpreter and look for pip packages in the wrong place.

Comments

0

azure metapackage is deprecated and azure-storage is not being maintained anymore

Please use azure-storage-blob >= 12.0

pip install azure-storage-blob 
from azure.storage.blob import BlobServiceClient 

PS: I write SDKs for azure

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.