1

OSX, PyCharm, with brew-installed python 2.7, simply trying to import

from azure.mgmt.common import SubscriptionCloudCredentials
import azure.mgmt.compute
import azure.mgmt.network
import azure.mgmt.resource
import azure.mgmt.storage

Got error:

/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/bin/python2.7 XXX/pythonCode/p2.1/azure.py
Traceback (most recent call last):
  File "XXX/pythonCode/p2.1/azure.py", line 9, in <module>
    from azure.mgmt.common import SubscriptionCloudCredentials
  File "XXX/pythonCode/p2.1/azure.py", line 9, in <module>
    from azure.mgmt.common import SubscriptionCloudCredentials
ImportError: No module named mgmt.common

Tried:

  • Reinstall azure from source

    https://github.com/Azure/azure-sdk-for-python

  • Running

    python -c "import site; print(site.getsitepackages())"

    I get ['/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages', '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/site-python', '/Library/Python/2.7/site-packages']

    In which /usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages contains azure

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

    I get

    '', '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages', '/usr/local/Cellar/numpy/1.10.4/libexec/nose/lib/python2.7/site-packages', '/Library/Python/2.7/site-packages'
    

Remarkably Running

python -c "from azure.mgmt.common import SubscriptionCloudCredentials"

in terminal does not error at all.

Can anyone explain where the problems are?

1

1 Answer 1

3

The problem is that the file in which you wrote your script in is called azure.py. This file is getting imported instead of the module azure that you installed, and it doesn't have the necessary attributes, resulting in this error.

Renaming the file your code is in to something else will fix this problem.

Sign up to request clarification or add additional context in comments.

1 Comment

My gosh. Exactly. What was I thinking. Thank you ppperry.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.