My first time using VS Code for Python development
Visual Studio Code, also commonly referred to as VS Code, is a source-code editor developed by Microsoft for Windows, Linux, macOS, and web browsers. Not to be confused with Microsoft's Visual Studio, which is an IDE, VS Code is more of a rich text editor.
A Python developer survey conducted in 2022 shows VS Code is the most popular main editor in the Python camp, even ranking above the Python-specific PyCharm IDE from JetBrains (which conducted the survey of more than 23,000 Python developers in conjunction with the Python Software Foundation).
Installing VS Code and Python Extension
VS Code can be downloaded from here. After installation, I clicked on "Install" for Python under the Extensions Marketplace. I then created my first Python file (copied from here). You'll notice that on the bottom of the editor it says "Select Interpreter". It seems that Python was not installed on my Microsoft Windows 11 workstation.
So I opened a command prompt and tried to run python3
from the command line. It didn't give me an error but it did give me the message: "Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases".
This automatically popped up the Microsoft Store app and I installed the Python 3.12 software.
Now I have Python installed, and then used pip3
to install the openai
package from the command line.
Running my First Python Program
Back to my editor, I was now ready to run my first Python code by clicking on the play button. The output is shown in the TERMINAL tab and worked as expected.
I did run into a few issues. First, the code couldn't find my training data, so I had to use a fully qualified path to the filename (see line 11 in the screenshot above). Then the openai
package was also missing, but I mentioned installing that earlier in this post.