简体   繁体   English

如何在 Visual Studio 2019 中将 python 代码与 C# 集成

[英]How to integrate python code with C# in Visual Studio 2019

Python code, which is executed on Google Colab and downloaded in.py file how to integrate it with C# code in Visual Studio 2019. On button click, Python code should execute in background and output should be displayed on WPF application. Python code, which is executed on Google Colab and downloaded in.py file how to integrate it with C# code in Visual Studio 2019. On button click, Python code should execute in background and output should be displayed on WPF application.

Python code can be executed in c# by IronPython library and via command prompt . Python 代码可以通过IronPython 库命令提示符在 c# 中执行。 In IronPython I feel some issues.在 IronPython 中我觉得有些问题。 So, I will suggest you to make a process and execute it by cmd.所以,我会建议你制作一个流程并通过cmd执行它。 Here is the code to do so.这是执行此操作的代码。

 ```Process proc = new Process();
            ProcessStartInfo info = new ProcessStartInfo();
            info.WindowStyle = ProcessWindowStyle.Normal;
            info.FileName = "cmd.exe";
            info.Arguments = "/C python code.py \""+arguments+"\""; 
            info.RedirectStandardOutput = true;
            info.UseShellExecute = false;
            info.CreateNoWindow = false;
            proc.StartInfo = info;
            proc.Start();
            proc.WaitForExit();
            string line = "";
            while (!proc.StandardOutput.EndOfStream)
            {
                line += proc.StandardOutput.ReadLine();

            }```

But you have to install all the libraries in PC first which must be overall in the PC not only in some folder.但是您必须首先在 PC 中安装所有库,这些库必须整体在 PC 中,而不仅仅是在某个文件夹中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 python 代码与 Visual Studio c# 集成 - Integrating python code with Visual Studio c# 如何在 Visual Studio 2019(不是 VS Code)中为 Python 禁用 JustMyCode - How to disable JustMyCode for Python in Visual Studio 2019 (not VS Code) 如何使用 python 代码在 Visual Studio 2019 中打开我的项目 - How to open my project in visual studio 2019 using python code 如何在Visual Studio的c ++,qt,vtk,itk环境中集成一段python代码? - How to Integrate a piece of python code in a c++,qt,vtk,itk environment in visual studio? 如何在 Visual Studio 2019 中清除 python 解释器 - How to clear python interpreter in visual studio 2019 C#代码无法在Visual Studio中运行完整的python脚本 - C# code do not run complete python script in visual studio Visual Studio 2019(不是 VS Code)显示不完整的 python 文档 - Visual Studio 2019 ( not VS Code ) shows incomplete python Documentation 将 Visual Studio 2019 调试器连接到 VS Code 中的 Python 进程 - Connect Visual Studio 2019 debugger to Python process in VS Code 如何在Python的Visual Studio(2019)中禁用滚动条旁边的代码预览/映射 - How to disable Code Preview/Map next to scrollbar in Visual Studio (2019) for Python 如何在执行代码时打开或关闭Visual Studio python(Jupyter)交互式窗口(2019)? - How do i turn on or off the Visual Studio python (Jupyter) interactive window (2019) when executing code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM