Tuesday, December 27, 2016

How to - configure Visual Studio Code with Python 3.5.2 virtual project

Hej all,

A small how-to on how to configure Visual Studio Code to launch the python interpreter for your current virtual environment you're working with.

1. Open your Python project folder in Visual Studio Code

2. In the folder root create a new directory -> ".vscode" (Skip this step if it's already there)

3. In the ".vscode" directory create a new file -> "settings.json"

Add the following text to this file and save :
{
    "python.pythonPath":"C:\\PATH\\TO\\YOUR\\VIRTUAL\\PROJECT\\FOLDER\\Scripts\\python",
    "python.autoComplete.extraPaths": [
        "C:\\PATH\\TO\\YOUR\\VIRTUAL\\PROJECT\\FOLDER\\Scripts",
        "C:\\PATH\\TO\\YOUR\\VIRTUAL\\PROJECT\\FOLDER\\Lib\\site-packages"
    ]
}
  • This will enable auto-complete, debug and to run the scripts with right-click on the file "Run python file in terminal"

4. In the ".vscode" directory create a new file -> "tasks.json"

Add the folowing text to this file and save :

{
"version": "0.1.0",
"command": "C:\\PATH\\TO\\YOUR\\VIRTUAL\\PROJECT\\FOLDER\\Scripts\\python",
"isShellCommand": true,
"showOutput": "always",
"args": ["${file}"]
}
  • This enables you to use "cntrl+shift+B" and run the actual selected script file
You simply restart Visual Studio Code and you're ready to go, happy coding !



1 comment: