【问题标题】:ModuleNotFoundError: No module named 'azure'ModuleNotFoundError:没有名为 \'azure\' 的模块
【发布时间】:2023-01-31 07:29:42
【问题描述】:

我正在尝试从 Windows 机器在msgraph-sdk-python-core 上运行一个 exe 文件。 exe 是由 PyInstaller 从一个简单的 python 文件创建的。

主程序

from azure.identity import ClientSecretCredential
from msgraph.core import GraphClient

def getGraphClient():

    client_secret_credential = ClientSecretCredential(
        tenant_id="tenant_id",
        client_id="client_id",
        client_secret="client_id")

    gRaphClient = GraphClient(credential=client_secret_credential)

    return gRaphClient

print(getGraphClient())
azure-core==1.26.1
azure-identity==1.12.0
certifi==2022.12.7
cffi==1.15.1
charset-normalizer==2.1.1
cryptography==38.0.4
idna==3.4
msal==1.20.0
msal-extensions==1.0.0
msgraph-core==0.2.2
portalocker==2.6.0
pycparser==2.21
pyinstall==0.1.4
PyJWT==2.6.0
pywin32==305
requests==2.28.1
six==1.16.0
typing_extensions==4.4.0
urllib3==1.26.13

在开发环境下运行正常,但是当我将其转换为Exe时,出现如下错误。

>main.exe
Traceback (most recent call last):
  File "main.py", line 1, in <module>
ModuleNotFoundError: No module named 'azure'
[19104] Failed to execute script 'main' due to unhandled exception!

我也试过 --hidden-import 'azure' 但它不起作用。 'azure' 已经停产了,你知道如何用 Exe 做这个吗?

【问题讨论】:

  • 尝试:pip install azure
  • 适用于 Python 的 Microsoft Azure SDK(pip install azure)“从 v5.0.0 开始,此包已弃用。请安装应用程序所需的以 azure 为前缀的服务特定包。” pip install azure 出现安装错误。

标签: python msgraph


【解决方案1】:

升级 pyinstaller 解决了它。

pip install --upgrade pyinstaller

【讨论】:

    【解决方案2】:

    pip install 对我不起作用。

    python --version 
    

    显示 Python 3.10.5

    做过这个:

    pip3 install azure-storage-blob azure-identity
    

    然后能够使用导入的 azure 功能。

    from azure.identity import DefaultAzureCredential
    from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-28
      • 1970-01-01
      • 2022-01-07
      • 2021-03-07
      • 2017-12-14
      • 2020-12-10
      • 2021-09-02
      相关资源
      最近更新 更多