在Azure中,我可以从C#WebJob中调用Python脚本吗? [英] In Azure, can I call a Python script from my C# WebJob?
问题描述
我想用C#创建一个WebJob.不幸的是,我需要使用Python 3脚本,因为当前没有适合我使用C#执行的一项特定任务的合适的库.
I want to create a WebJob in C#. Unfortunately, I need to use a Python 3 script as there is currently no suitable library for 1 particular task that I need to perform, using C#.
例如,请参见 answer/example .
是否可以让我的WebJob调用Python脚本?我可以将Python3脚本放在blob容器中-然后我可以从C#WebJob调用并执行它了吗?
Is it possible to have my WebJob call a Python script? I can place the Python3 script in a blob container - would I then be able to call and execute it from my C# WebJob?
推荐答案
Sure, it's possible to call a Python 3 script via C# WebJob that follow the sample you linked. First of all, you need to install a Python 3 runtime as below.
- 通过URL
https://<your webapp name>.scm.azurewebsites.net
访问kudu工具,并按照下图安装Python 3运行时. - 例如要安装
Python 3.5.2 x86
,它将安装在路径D:\home\Python35
中,那么您只需更改示例中的Python执行文件路径即可尝试运行它.
- Access the kudu tool via the url
https://<your webapp name>.scm.azurewebsites.net
, and follow the figure below to install a Python 3 runtime. - For example to install
Python 3.5.2 x86
, it will be installed in the pathD:\home\Python35
, then you just need to change the Python execute file path in the sample to try to run it.
希望有帮助.
更新:安装pip
工具&其他Python软件包.
Update: Install pip
tool & other Python packages.
- 访问网址
https://<your azure webapp name>.scm.azurewebsites.net/DebugConsole
. -
命令如下.
- Access the url
https://<your azure webapp name>.scm.azurewebsites.net/DebugConsole
. Commands as below.
D:\home>cd Python35
D:\home\Python35>curl https://bootstrap.pypa.io/get-pip.py --output get-pip.py
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1558k 100 1558k 0 0 6829k 0 --:--:-- --:--:-- --:--:-- 7179k
D:\home\Python35>python get-pip.py
Requirement already up-to-date: pip in d:\home\python35\lib\site-packages
Collecting wheel
Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
Installing collected packages: wheel
Successfully installed wheel-0.29.0
例如,安装numpy
软件包
D:\home\Python35>python get-pip.py numpy
Collecting numpy
Downloading numpy-1.13.1-cp35-none-win32.whl (6.8MB)
Installing collected packages: numpy
Successfully installed numpy-1.13.1
这篇关于在Azure中,我可以从C#WebJob中调用Python脚本吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!