How to integrate Python with ASP.NET

MHT picture MHT · Nov 10, 2016 · Viewed 9.6k times · Source

I am making an ASP.NET website in which I would like to use some python 3.x code. Not exactly 'some', but a lot.

I have started searching for a solution but not exactly reached a good one yet. I am using VS 2015, and most of the solutions I found were for VS 2010, 2012. But not for VS 2015.

So I began with installing the PTVS, but that ends up in an error. Screenshot of error.

Please help regarding the installation error and how to set up the integration.

Thanks a bunch.

Answer

0x49D1 picture 0x49D1 · Nov 10, 2016

If you don't need exactly python 3 - take a look at IronPython (latest version is 2.7 compatible). For example: Running IronPython Scripts from a C# 4.0 Program.
If you just need to use Python script from your your .NET project - you can just ask python.exe to run the script. Something like this:

ProcessStartInfo p = new ProcessStartInfo();
p.FileName = @"\Path\to\python\interpreter\python.exe";
p.Arguments = @"\Path\to\*.py";
p.CreateNoWindow = false;
p.UseShellExecute = true;
Process procScriptExecutor = Process.Start(p);
procScriptExecutor.WaitForExit();
procScriptExecutor.Close();