Use Python In Visual Studio Code



  • The Python extension for Visual Studio Code. The Azure Functions extension for Visual Studio Code. Create your local project In this section, you use Visual Studio Code to create a local Azure Functions project in Python.
  • Start Python interactive mode to run Python code one line at a time. Install Visual Studio Code, Python, and the Python extension for Visual Studio Code on your computer. Create a Python script file and write Python code in Visual Studio Code. Run your Python script file code by using the Python command-line tools.
Use Python In Visual Studio Code

Since Visual Studio Code can use whichever version of Python in your system, you need to install modules for that specific version used. Once you realize this, solution is straightforward, just install module with pip using the same version of Python chosen as interpreter (Figure 2) using directly python.exe correct version as shown in Figure 3.

Visual Studio Code Download Python

I’m not a Python expert, but I used it more often these days and I use Visual Studio Code with Python extension to author my scripts. One of the most annoying problem is receiving a no module named xxx error when you already installed that module with pip.

Figure 1:No module error when running Python code in Visual Studio Code

The problem arise because Visual Studio Code is not using the very same installation of python you are using from your command line / terminal. When you edit Python files in Visual Studio Code you should select interpreter path command to specify which version of Python you want to use, as showed in Figure 2:

Python In Visual Studio

Figure 2:Choose Python interpreter

Python in visual studio code 2019

This allows you to choose which Python version you want to use, but clearly, when you press F5 that specific version is used and probably you did not install required module in that specific version.

Since Visual Studio Code can use whichever version of Python in your system, you need to install modules for that specific version used.

Using Visual Studio Code For Python

Once you realize this, solution is straightforward, just install module with pip using the same version of Python chosen as interpreter (Figure 2) using directly python.exe correct version as shown in Figure 3.

Figure 3:Install modules with right version of pip

Once you installed modules using the very same version chosen as interpreter in VSCode, you are ready to go. Pressing F5 you can now debug your code without problem.

Can I Use Python In Visual Studio Code

Figure 4:Debugging in VSCode after installing required modules

This simple trick should solve the problem.

Shortcut To Run Python In Visual Studio Code

Gian Maria.