Resources

https://code.visualstudio.com/docs/python/python-tutorial

Creating a new Python project

VS Code menu > File > Open Folder

Open a folder that will be your workspace (you can just open an empty folder you’ve created).

Turn off Dropbox if your folder is within Dropbox (causes file access issues for us at times)

Now create a virtual environment for this project (recommended approach when using Python, so individual projects and their dependencies are kept isolated from each other).
Open the Command Palette (Ctrl+Shift+P) and enter “Python: Create Environment”
Select “Venv” (default, or whatever you want to use)
Select the interpreter to use (the version of Python you’ve installed on your machine).
Wait for the progress to complete. Check for any errors.

Create a new file

Menu > File > New file… > MyFileName.py

Running the Project

Use the play button at the top right of the code editor window “Run Python File”.

Debugging the project

Press F5

Or use the dropdown option on the play button at the top right of the code editor window and select “Debug Python File”.

Then use menu > Run options to control debugging.

There is also the left “Run and Debug” panel which shows various debug info.

Install python packages you want to use in your code

Open the Command Palette (Ctrl+Shift+P) and enter “Terminal: Create New Terminal” to create a powershell terminal window.

Say you want to install the “requests” python package:

py -m pip install requests

Troubleshooting

If there are errors creating the virtual environment

This page may help

Right click the Output window and select “Clear output” before trying again, so you are not looking at old errors.

If you make changes to try and fix, you can delete the .venv directory and try again (seems to work better than telling VS code to do it when running “Python: Create Environment” again in our experience).

USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through resources like this. We hope you find it helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support here. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published. Required fields are marked *