gpt4 book ai didi

Python 2.7 运行 py 时找不到模块。但可以在终端中找到模块

转载 作者:行者123 更新时间:2023-11-30 23:00:50 24 4
gpt4 key购买 nike

OSX,PyCharm,带有brew安装的python 2.7,只是尝试导入

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

出现错误:

/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

尝试过:

  • 从源重新安装 azure

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

  • 正在运行

    python -c“导入站点;打印(site.getsitepackages())”

    我明白了['/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']

    其中/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages包含azure

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

    我明白了

    '', '/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'
<小时/>

非常明显正在运行

python -c“来自 azure.mgmt.common 导入 SubscriptionCloudCredentials”

在终端中根本没有错误。

谁能解释一下问题出在哪里吗?

最佳答案

问题是您编写脚本的文件名为 azure.py。导入的是此文件,而不是您安装的 azure 模块,并且它没有必要的属性,从而导致此错误。

将代码所在的文件重命名为其他文件可以解决此问题。

关于Python 2.7 运行 py 时找不到模块。但可以在终端中找到模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35139780/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com