简体   繁体   English

pytz 问题 package - Python - Azure Z86408593C34AF77FDD90BDF9

[英]Problem with pytz package - Python - Azure Function

I had an Azure function that worked completely fine, then I added the pytz package to my script.我有一个运行良好的 Azure function,然后我将 pytz package 添加到我的脚本中。

In Azure I am getting the error:在 Azure 我收到错误:

ModuleNotFoundError: No module named 'pytz'. ModuleNotFoundError:没有名为“pytz”的模块。

My requirements.txt file looks like this:我的 requirements.txt 文件如下所示:

azure-functions
pyodbc==4.0.32
requests==2.28.0
pytz==2022.1

and the top of my actual script looks like this:我的实际脚本的顶部如下所示:

import datetime
import logging
import requests
import json
import pyodbc
import azure.functions as func
from datetime import datetime
from pytz import timezone

When I deploy the function from Python, I can see the packages getting installed in the output EXCEPT for pytz.当我从 Python 部署 function 时,我可以看到包安装在 output 中,除了 pytz。 Is it because in my script it is written as 'from pytz'?是因为在我的脚本中它被写为“来自 pytz”吗? I am very new to Python and appreciate any help.我对 Python 非常陌生,感谢任何帮助。

Microsoft has given a solution and troubleshooting steps for this kind of error with detailed explanation that: Microsoft 已针对此类错误提供了解决方案和故障排除步骤,并详细说明:

The Module Not Found error may not occur when you're using Windows or macOS for local development.使用 Windows 或 macOS 进行本地开发时,可能不会出现 Module Not Found 错误。 However, the package fails to import on Azure Functions, which uses Linux at runtime.但是,package 无法在 Azure 函数上导入,该函数在运行时使用 Linux。 This is likely to be caused by using pip freeze to export virtual environment into requirements.txt这很可能是使用 pip freeze 将虚拟环境导出到 requirements.txt 导致的

To mitigate this error, there are 2 solutions given by Microsoft which are replace the equivalent package or Handcraft requirements.txt file.为了缓解此错误,Microsoft 提供了 2 个解决方案,它们替换了等效的 package 或 Handcraft requirements.txt 文件。

Check this document given by Microsoft.检查 Microsoft 提供的此文档

After reproducing from my end, In my case the problem was with the python environment.从我的角度复制后,在我的情况下,问题出在 python 环境中。 Though the python environment is present make sure you activate the environment.尽管存在 python 环境,但请确保激活该环境。

在此处输入图像描述

After activating ie, <Your_Environment_Name>\Scripts\Activate.ps1激活<Your_Environment_Name>\Scripts\Activate.ps1

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM