Python 2.7 cannot find module when running py. But can find module in terminal
Question: 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?


Answer: 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.

