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.

M3579
  • 850
  • 2
  • 10
  • 21
  • There is some great [article about integrating a Lua interpreter into UWP](http://blogs.u2u.be/diederik/post/2015/10/29/Extend-your-UWP-apps-with-Lua-scripting.aspx) - maybe this can also be done using IronPython? – sibbl Nov 01 '15 at 13:12

1 Answers1

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.

Antoine C.
  • 3,193
  • 3
  • 26
  • 51
  • 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. – M3579 Nov 01 '15 at 18:05
  • Nope, due to sandboxing, executing an embedded or an external executable is absolutely impossible. You need to add the DLLs as shared libraries – Antoine C. Nov 01 '15 at 18:21
  • 1
    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. – Lee McPherson Dec 12 '17 at 07:05
  • 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://stackoverflow.com/a/44006005/7347121 Communication between appcontainer-programs and non-appcontainer-programs can be achieved easily by using inherited handles. – z0rberg's Sep 03 '20 at 07:11