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?

AntonZ
  • 91
  • 1
  • 9
  • Possible duplicate of [Importing installed package from script raises "AttributeError: module has no attribute" or "ImportError: cannot import name"](https://stackoverflow.com/questions/36250353/importing-installed-package-from-script-raises-attributeerror-module-has-no-at) – pppery Aug 19 '19 at 13:47

1 Answers1

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.

pppery
  • 3,731
  • 22
  • 33
  • 46