个人实践,如何在vs2017或vs2019中搭建python环境,并与c#混合

系统 1907 0

本来已经安装了anaconda,不过想更进一步,试试c#与python混合编程。
我记得微软的vs2017,vs2019已经支持了python,如果能用一个IDE搞定全部,自然是最好的。

首先理解vs2017编译器是怎么支持python的。

① 按照微软的说法,Visual Studio 的“Python 环境”窗口(下方为其扩展后的加宽视图)具有一块用于管理所有全局 Python 环境、conda 环境和虚拟环境的单独区域 。 Visual Studio 可自动检测出标准位置是否安装 Python,并且允许用户配置自定义安装。 在每个环境中,用户都可以轻松管理包、打开该环境的交互窗口和访问环境文件夹。

总结-----visual studio能当大管家,电脑里安装了其他python环境也没问题。
个人实践,如何在vs2017或vs2019中搭建python环境,并与c#混合编程(一)_第1张图片

Use the Open interactive window command to run Python interactively within the context of Visual Studio. Use the Open in PowerShell command to open a separate command window in the folder of the selected environment. From that command window you can run any python script.
For every Python environment known to Visual Studio, you can easily open the same interactive (REPL) environment for a Python interpreter directly within Visual Studio, rather than using a separate command prompt. You can easily switch between environments as well. (To open a separate command prompt, select your desired environment in the Python Environments window, then select the Open in PowerShell command as explained earlier under Support for multiple interpreters.)

使用“ Open interactive window” 命令,在 Visual Studio 的上下文中以交互方式运行 Python。 使用“open PowerShell 中” 命令,在所选环境的文件夹中打开单独的命令窗口。 可从该命令窗口运行任何 python 脚本。

对于 Visual Studio 已知的每个 Python 环境,用户都可以直接在 Visual Studio 中轻松打开 Python 解释器的实时交互 (REPL) 环境,而无需使用单独的命令提示符。 也可以轻松地切换环境。 (若要打开单独的命令提示符,请在“Python环境”窗口中选择所需的环境,然后如之前的对多个解释器的支持下所述,选择“在 PowerShell 中打开”命令)
个人实践,如何在vs2017或vs2019中搭建python环境,并与c#混合编程(一)_第2张图片

总结-----微软提供了两个交互方式,一个叫做interactive window,这是一种实时交互环境,能随时查看运行结果,变量的值。
另一种叫做 PowerShell 命令行窗口,这是单独用来执行任何py程序的。

Visual Studio also provides tight integration between the Python code editor and the Interactive window. The Ctrl+Enter keyboard shortcut conveniently sends the current line of code (or code block) in the editor to the Interactive window, then moves to the next line (or block). Ctrl+Enter lets you easily step through code without having to run the debugger. You can also send selected code to the Interactive window with the same keystroke, and easily paste code from the Interactive window into the editor. Together, these capabilities allow you to work out details for a segment of code in the Interactive window and easily save the results in a file in the editor.
Visual Studio also supports IPython/Jupyter in the REPL, including inline plots, .NET, and Windows Presentation Foundation (WPF).

Visual Studio 还紧密集成了 Python 代码编辑器与Interactive window。 使用 Ctrl +Enter 键盘快捷方式可将编辑器中的当前代码行(或代码块)发送给交互 窗口,然后移至下一行(或块),Ctrl +Enter 无需运行调试程序即可轻松单步执行代码。 你也可以使用相同的键盘快捷方式将选定代码发送给Interactive window,并轻松地将Interactive window中的代码粘贴到编辑器中。 将这些功能结合使用可以在Interactive window中找出代码段的详细信息,并将结果轻松保存到编辑器的文件中。

总结:Ctrl +Enter功能很牛X。

Visual Studio helps you manage the complexity of a project as it grows over time. A Visual Studio project is much more than a folder structure: it includes an understanding of how different files are used and how they relate to each other. Visual Studio helps you distinguish app code, test code, web pages, JavaScript, build scripts, and so on, which then enable file-appropriate features. A Visual Studio solution, moreover, helps you manage multiple related projects, such as a Python project and a C++ extension project.

Visual Studio 可帮助管理项目随时间增加的复杂性。 Visual Studio 项目不仅仅是一个文件夹结构:它包括理解不同文件的使用方式以及文件之间的关系。 Visual Studio 可帮助用户区分应用代码、测试代码、网页、JavaScript 和生成脚本等,从而启用文件对应的功能。 此外,Visual Studio 解决方案还可以帮助用户管理多个相关的项目,例如 Python 项目和 C++ 扩展项目。
个人实践,如何在vs2017或vs2019中搭建python环境,并与c#混合编程(一)_第3张图片
总结: 发挥ide的优势,能系统的管理项目,具备很多内置的模板,项目和项模板可自动完成不同类型的项目和文件的设置过程,能为用户节省宝贵的时间,无需管理错综复杂又容易出错的细枝末节。

⑤司空见惯的智能提示,全面的 Python 调试,使用基于 CPython 的解释器时,可以在 Visual Studio 中评估 Python 代码的性能。

以及Linting 检查,Python 代码中的错误和常见问题,鼓励使用好的 Python 编码模式。
为 Python 创建的许多库都是用 C++ 编写的,旨在获得最佳性能。 Visual Studio 提供了丰富的用于开发 C++ 扩展的工具,包括混合模式调试。
总结:所以c++与python在vs中能很好的结合?这个还没研究过,而linting在anaconda中没有?

缺点: 因为python通常是一种解释型语言目前,Visual Studio 本身不提供创建独立可执行文件的方法,它本质上是一个具有嵌入式 Python 解释器的程序。另外,Visual Studio 中的 Python 支持不包括用于 UI 开发的任何特定工具。
我记得没错的话,python的UI一直是弱项,没有也无所谓。


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论