zipfile

问题描述

我在一个名为fgh.py的文件中有以下小脚本,我一直试图将其安排为网络作业

import pandas as pd

df=pd.DataFrame({'a':[1,2,2],'b':[5,6,9]})

df['x']=df.a.sub(df.b)

print(df)

使用@Peter Pan post。我创建了一个虚拟环境,完成了pip install pandas。在虚拟环境中,脚本会根据需要运行并执行。但是,在加载到Azure Webjobs中时脚本不会执行。我怀疑问题是由于run,bat文件与Azure python控制台之间的接口引起的,但是对Azure的了解有限,无法解决问题

在kudus中,我已使用此post安装python。

where python的{​​{1}}命令中运行cmd,我得到了;

enter image description here

另外,从https://myapp.scm.azurewebsites.net/DebugConsole运行cmd命令https://arcgistrial.scm.azurewebsites.net/DebugConsole时,我得到以下内容

enter image description here

在我的python -V文件中,我尝试使用上面的任何一个目录都没有成功。

无论我制作run.bat文件run.bat还是D:\home\python364x64\python.exe fgh.py我都会遇到以下错误;

enter image description here

我全力以赴并安装了D:python364x64\python.exe fgh.py,并通过尝试安装pandas来检查是否成功

enter image description here

所有这些都无济于事。我已经做了几天,它必须以某种方式工作。有帮助吗?

解决方法

(在旧的Webjobs中运行具有依赖性的python任务并不是一件很简单的事情。已经有一段时间了,世界已经转移到Azure Function:))

但是,由于您仍然需要坚持使用Webjobs,因此以下是我遵循的有效步骤。由于先决条件,我正在使用批处理文件(.cmd)运行python脚本。

  1. 默认情况下,webjob目前支持python 2.7。因此,在您的Web应用程序中从“扩展”中添加python3,在本例中为3.6.4 x64。这将添加到路径D:\home\python364x64\中。我怎么知道Kudus控制台:)

enter image description here

  1. 创建一个包含requirements.txtpandas的{​​{1}}文件(请注意,由于an issue在Windows中的最新版本为1.19.4,我必须显式添加numpy版本1.19.3。在撰写本文时担任主持人)。基本上,我使用的是numpy,它取决于fgh.py,而后者又取决于pandas
numpy
  1. 创建一个具有以下内容的pandas==1.1.4 numpy==1.19.3 文件。注意不需要第一行。我只是在检查python版本。
run.cmd
  1. D:\home\python364x64\python --version D:\home\python364x64\python -m pip install --user --upgrade pip D:\home\python364x64\python -m pip install --user certifi D:\home\python364x64\python -m pip install --user virtualenv D:\home\python364x64\python -m virtualenv .venv .venv\Scripts\pip install -r requirements.txt .venv\Scripts\python fgh.py fgh.pyrun.bat文件压缩为单个zip。以下是我的zip的内容。

enter image description here

  1. 上传Webjob的zip。
  2. 执行任务:)

enter image description here enter image description here

忽略错误“ ModuleNotFoundError:没有名为'certifi'的模块”。

,

解决此问题的关键是您需要在Azure上创建venv环境。

第1步。在本地成功运行。

enter image description here

第2步。压缩您的webjob文件。

enter image description here

第3步。上传webjob压缩文件。

由于测试环境之前拥有python1,因此稍后我将创建python2的webjob。

enter image description here

enter image description here

第4步。登录Kudu。

cd .. enter image description here

②找到Python34,单击它。

enter image description here

python -m venv D:\home\site\wwwroot\App_Data\jobs\continuous\python2\myenv

enter image description here

④查找myenv文件夹。

enter image description here

⑤活动的myenv,输入.\activate.bat

D:\ home \ site \ wwwroot \ App_Data \ jobs \ continuous \ python2 \ myenv \ Scripts>。\ activate.bat

enter image description here

⑥返回python2文件夹,然后输入pip install pandas

enter image description here

⑦然后输入python aa.py

enter image description here

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...