简体   繁体   中英

Azure - numpy - OSError: [WinError 193] %1 is not a valid Win32 application

I am attempting to schedule Python scripts to run on a regular basis using Azure. Following the steps here , I have created a WebJob inside a Web App. To the WebJob I have uploaded .zip folder containing my Python script and these modules .

My code is very simple:

import pandas as pd

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

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

print(df)

On running the WebJob, I get the following error:

[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

How can I solve this?

According to your error information, obviously the issue was caused by the Python script inside your WebJob zip file which is not an executable file for your current Azure WebApp. So please check your configuration on Azure portal whether be set correctly for Stack settings as the figure below.

在此输入图像描述

Otherwise, if the above operation can not fix it for your current WebApp instance, a workaround solution is to add a .bat file into your WebJob zip file as a startup file to help running your Python script, because Azure WebApp default supports .cmd , .exe , .bat using Windows cmd, please refer to the section Supported file types for scripts or programs of the offical document Run Background tasks with WebJobs in Azure App Service to know it.

And for example to add a file named run.bat , the code using python.exe (version 3.6.6 ) in the absolute Python path D:\\Python34\\ as below.

D:\Python34\python.exe Test12.py

Hope it helps. Any concern, please feel free to let me know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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