Windows 通用应用程序:从 C# 调用 python 方法 [英] Windows Universal Apps: Call python method from C#

查看:101
本文介绍了Windows 通用应用程序:从 C# 调用 python 方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 .py 文件,我想调用它并获取它在我的应用程序中返回的值.

I have a .py file I want to call and get the value it returns in my App.

我的主要目的是在基于 C# 的通用应用程序中使用 scikit-learn 进行机器学习,我将如何实现?

My main intention is to use scikit-learn for machine learning within my C#-based Universal App, how would I accomplish that?

推荐答案

在 UWP 中,您的选择非常有限.通用应用程序在沙箱中运行,并且在如何与经典桌面应用程序(例如 Python)交互方面受到限制,这会阻止您使用本地 Python 安装简单地外壳执行"您的脚本.

In UWP your options are pretty limited. Universal applications run in a sandbox and are restricted in how they can interact with classic desktop applications, such as Python, which prevents you from simply "shell-executing" your script using the local Python installation.

有一种方法可以在 Windows 8.1 WinRT 中使用 代理组件,但应用程序需要侧载;它不适用于从商店安装的应用程序.当然,它需要 Windows 的桌面版本,也不能在 Windows Phone 上运行.此外,我没有看到任何与 Windows 10 UWP 相关的提及,我严重怀疑它仍然有效.

There was a way to do it in Windows 8.1 WinRT using brokered components, but the application needed to be sideloaded; it wouldn't work with applications installed from store. Of course, it required the desktop version of Windows and didn't work on Windows Phone, either. Also, I didn't see any mention of this in relation to Windows 10 UWP and I seriously doubt it still works.

可能最好的办法是尝试 CPython 的 UWP 版本.我从未使用过它,我不知道它的状态,我也不知道要让 scikit-learn 在其中工作需要付出多少努力.但是,如果您希望您的应用程序在多个平台(桌面、移动、物联网...)上运行,我不知道还有其他选择.

Probably your best bet is to try the UWP version of CPython. I never used it, I don't know the state it is in and I have no idea, how much effort would be required to get scikit-learn working in it. But if you want your application to work on multiple platforms (desktop, mobile, IoT...), I don't know of another option.

另一方面,如果您只针对桌面,我建议您放弃使用 UWP,而是创建一个经典的桌面应用程序.这将允许您不受任何限制地使用标准 CPython 版本,方法是调用本地安装的版本或将其嵌入到您的应用中.

On the other hand, if you're only targeting desktop, I would suggest you abandon the use of UWP and create a classic desktop application instead. This will allow you to use the standard CPython version without any restrictions, either by invoking the locally installed version or by embedding it into your app.

这篇关于Windows 通用应用程序:从 C# 调用 python 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆