This is a quick tutorial to explain how to use Python in Visual Studio. If you are from a programming background, then I am sure that you must have heard about Visual Studio. Also, you know that it is used for doing programming in C++, Visual Basics, C#. etc. But, if you want to use another programming language like Python, then you can also do that. Actually, there is a plugin for Visual Studio that helps you to write and compile Python code in Visual Studio. You can use Visual Studio as an IDE for Python programming and with all features like compiling, running, debugging a program. Python tools for Visual Studio or PTVS for shorts is a plugin for Visual Studio that lets you use Visual Studio as an IDE for Python. The plugin adds the functionality of Python in Visual Studio and when you will use it, it will give you the feeling that you are actually using an IDE that gives you code suggestion, auto-complete code & keywords, code highlighting, etc.
How To Use Python In Visual Studio?
I have already mentioned above that you will need PTVS plugin to add Python functionality to Visual Studio. After that, you will be able to write Python code in Visual Studio and also run it from there. It will automatically detect the Python installation folder and will use the Python interpreter to run the code. And not only a Python application, you will also be able to write code for Python class, package, Django app, and IronPython WPF window. When you are done creating your project, you can save it. And it will be saved in the same manner as other Visual Studio projects are saved. A Solution file will be there that will save the configuration. And it will use the default project directory to save the Python project.
Here are few steps to use Python in Visual Studio:
Step 1: Download PTVS from Microsoft’s GitHub page. After that, install the MSI file that you get from there. And after the installation, you can run the Visual Studio.
Step 2: Now, when you run Visual Studio and create a new project in it, you will notice a Python section in the installed application templates. When you click on Python, it will show you the list of various types of applications that you can create. Step 3: I have chosen Python application to write a console program. You can see the following screenshot. And Visual Studio automatically highlights the code and assists you via its code suggestion feature. Step 4: Now, to compile Python in Visual Studio, you can use the native Run button of Visual Studio. And it will open the Python interpreter which will execute your code and will show you the output. So, this is how you can easily use Python in Visual Studio. And PTVS plugin makes it very simple to do that. You can now create your application in Visual Studio and run it from there.
Visual Studio no doubt is one of the Best IDE for .Net programming and I am amazed by the fact that I can actually write and execute Python code from it as well. Code auto complete, syntax highlighting are other major advantages. So, if you are a Python developer, then you can try it.