ImportError: cannot import name Session, when using Azure SDK

前端 未结 2 1087
你的背包
你的背包 2021-01-16 00:58

I am running code using Azure SDK.

First, I download the sdk by pip install azure. Then I write to run the following python code.

impor         


        
相关标签:
2条回答
  • 2021-01-16 01:00

    I had recently upgraded my requests library using sudo (sudo pip install --upgrade requests), and then I was surprised that I couldn't just call the code without sudo.

    It couldn't locate the files it just upgraded due to a permissions issue!

    0 讨论(0)
  • 2021-01-16 01:22

    It seems that the issue was caused by the package requests as the same name as the python file or directory includes file __init__.py at the current directory.

    Because Python imports packages in order from the paths sys.path, and the first path is '' (current directory).

    So if you create a python file requests.py or create a dir requests include a file __init__.py, Python firstly imports it as the package requests. Then, running the code from requests import Session will cause the error ImportError: cannot import name Session.

    Please check the current directory or dirs in the paths sys.path in order and remove the file named requests.py or the dir named requests.

    0 讨论(0)
提交回复
热议问题