Use Python alongside C# in Windows UWP app
Asked Answered
F

1

6

I started writing an application in Python, but I now want to switch to C# and UWP. I know that you cannot write a UWP app in Python, but I am trying to see if I can write some code in Python and access that code from C#.

For example, writing a class in Python that C# code can access as well. Is that possible? And if so, can Python access Microsoft's UWP APIs?

The main code will not be written in Python; that would be impossible. But can interoperability between C# and Python exist, perhaps with IronPython (.NET's Python)?

And how would I set up such a Visual Studio project? I have Python Tools for Visual Studio installed, but there was no built-in option to add a Python file to my UWP app.

Figureground answered 31/10, 2015 at 23:7 Comment(1)
There is some great article about integrating a Lua interpreter into UWP - maybe this can also be done using IronPython?Foremost
C
5

'Classic' python interpreters in c# (as IronPython) don't work in store apps because of framework restrictions, as you run your app through a sandbox.

Some dude has ported the full python interpreter to WinRT on mercurial. Of course, due to framework restrictions, the whole standard library isn't available. This works with WinRT, so it will very likely work on UWP.

Charters answered 1/11, 2015 at 17:55 Comment(4)
Thanks. Is there a way to execute a .exe file in UWP? I have copied ipy.exe and the other files in its directory into my project and am now trying to use C# to execute it.Figureground
Nope, due to sandboxing, executing an embedded or an external executable is absolutely impossible. You need to add the DLLs as shared librariesCharters
In order to run .exe files that do some specific task for my UWP apps, I have resorted to putting them on Azure and running them behind a RESTful API. It works pretty well. Your app makes a REST call to your server which runs the .exe with whatever parameters you stick into the REST call. It spits the result out and the server sends it back.Dynamiter
I feel like this needs some corrections for accuracy. Appcontainer-sandboxed desktop programs can create child processes if they have the right, or - with default rights/permissions - if the appcontainer-sandboxed program is the command-line and the full path to the executable is known. Source: my last few days of experimenting. Also this link might be helpful: https://mcmap.net/q/464240/-how-to-execute-process-commands-or-similar-using-a-universal-windows-platform-uwp-app Communication between appcontainer-programs and non-appcontainer-programs can be achieved easily by using inherited handles.Slating

© 2022 - 2024 — McMap. All rights reserved.