Azure-numpy-OSError:[WinError 193]%1不是有效的Win32应用程序

时间:2019-06-17 16:52:19

标签: python azure numpy

我试图安排Python脚本使用Azure定期运行。按照步骤here,我在Web应用程序中创建了一个WebJob。我已将包含我的Python脚本和these modules的.zip文件夹上载到WebJob。

我的代码很简单:

import pandas as pd

A = [1,2,3,4]
B = ['a','b','c','d']

df = pd.DataFrame({'a':A,'b':B})

print(df)

在运行WebJob时,出现以下错误:

[06/17/2019 16:48:27 > e6e459: SYS INFO] Status changed to Initializing
[06/17/2019 16:49:01 > e6e459: SYS INFO] Run script 'Test12.py' with script host - 'PythonScriptHost'
[06/17/2019 16:49:01 > e6e459: SYS INFO] Status changed to Running
[06/17/2019 16:49:01 > e6e459: ERR ] Traceback (most recent call last):
[06/17/2019 16:49:01 > e6e459: ERR ]   File "Test12.py", line 1, in <module>
[06/17/2019 16:49:01 > e6e459: ERR ]     import pandas as pd
[06/17/2019 16:49:01 > e6e459: ERR ]   File "D:\local\Temp\jobs\triggered\Test12\2bjz15ce.qpm\pandas\__init__.py", line 13, in <module>
[06/17/2019 16:49:01 > e6e459: ERR ]     __import__(dependency)
[06/17/2019 16:49:01 > e6e459: ERR ]   File "D:\local\Temp\jobs\triggered\Test12\2bjz15ce.qpm\numpy\__init__.py", line 142, in <module>
[06/17/2019 16:49:01 > e6e459: ERR ]     from . import core
[06/17/2019 16:49:01 > e6e459: ERR ]   File "D:\local\Temp\jobs\triggered\Test12\2bjz15ce.qpm\numpy\core\__init__.py", line 23, in <module>
[06/17/2019 16:49:01 > e6e459: ERR ]     WinDLL(os.path.abspath(filename))
[06/17/2019 16:49:01 > e6e459: ERR ]   File "D:\Python34\lib\ctypes\__init__.py", line 348, in __init__
[06/17/2019 16:49:01 > e6e459: ERR ]     self._handle = _dlopen(self._name, mode)
[06/17/2019 16:49:01 > e6e459: ERR ] OSError: [WinError 193] %1 is not a valid Win32 application
[06/17/2019 16:49:01 > e6e459: SYS INFO] Status changed to Failed
[06/17/2019 16:49:01 > e6e459: SYS ERR ] Job failed due to exit code 1

我该如何解决?

1 个答案:

答案 0 :(得分:0)

根据您的错误信息,很明显,此问题是由WebJob zip文件(不是当前Azure WebApp的可执行文件)中的Python脚本引起的。因此,请检查Azure门户上的配置是否为Stack settings正确设置,如下图。

enter image description here

否则,如果上述操作不能为您当前的WebApp实例解决,则解决方法是将.bat文件作为启动文件添加到WebJob zip文件中,以帮助运行Python脚本,因为Azure WebApp默认使用Windows cmd支持.cmd.exe.bat,有关详细信息,请参考官方文档Run Background tasks with WebJobs in Azure App Service的{​​{3}}部分。

例如,要添加一个名为run.bat的文件,该代码在绝对Python路径python.exe中使用3.6.6(版本D:\Python34\),如下所示。

D:\Python34\python.exe Test12.py

希望有帮助。如有任何疑问,请随时告诉我。