Installing Visual Studio for Python

I will use Visual Studio Community as the development environment for writing Python programs. It is available for free from Microsoft’s Visual Studio website. It’s easiest if you Google ‘Visual Studio Community’, since the version will probably change over the coming months. I’m using the 2019 version.

From this site, you will download the Visual Studio installer. After selecting the components you want installed, the installer will download these and install them for you. The process can take quite a while, so be patient.

For Python development, you need to select (not surprisingly) the ‘Python development’ option in the installer.

The current installation uses Python version 3.7. Earlier versions (in particular version 2 and its variants) have some differences in syntax and function names, but I won’t consider those in these tutorials.

Once this is done, you can open Visual Studio by clicking on its icon, as usual. To test that the Python interpreter is working, select ‘Continue without code’ at the bottom of the ‘Get started’ menu.

When the main window of Visual Studio opens, you should get a Python interactive console at the bottom of the window:

If nothing appears, you can show the Python console by typing Alt+I (Alt key and capital ‘I’), or from the Tools menu, via Tools>Python>Python Interactive Window.

You can test the interpreter by entering some simple arithmetic expressions, such as 2+2. In its simplest form, the Python interpreter can be used as an ordinary calculator.

The PowerShell

Although you can run most Python commands from the console as described above, some series of Python statements do not run properly in this console. To run Python in the same way as you would from a command line outside of Visual Studio, you can do the following.

From Visual Studio’s View menu, select View>Other windows>Python environments. You’ll get the Python Environments panel on the right of the Visual Studio window:

Click on “Open in PowerShell” and you’ll get a separate console window with a prompt showing the directory where Visual Studio has installed Python. Type ‘python’ at this prompt and you’ll be in a proper independent Python console, where you can type Python commands interactively.

Congratulations! You’re now ready to start writing Python programs.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.