Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run python programs in visual studio code in virtualenv

I am currently running python programs in virtualenv but how can I run using visual studio code especially when run/debug is clicked. (Ubuntu)

First I need to be inside the environement this is what I run from terminal source ~/home/python/bin/activate and then python test.py where python is pointing to python3.5 in virtualenv

Basically I want to debug by using breakpoints.

like image 691
Sharath Avatar asked May 03 '17 10:05

Sharath


3 Answers

please edit launch.json Add Configuration

{
            "name": "Attach (Remote Debug)",
            "type": "python",
            "request": "attach",
            "localRoot": "${workspaceRoot}",
            "remoteRoot": "${workspaceRoot}",
            "port": 3000,
            "secret": "my_secret",
            "host": "localhost"
},

Follow link: https://code.visualstudio.com/docs/editor/debugging

like image 89
Mr.Van Avatar answered Oct 08 '22 21:10

Mr.Van


Assuming you are using the donjayamanne.python plugin for Visual Studio Code you can set this in the User or Workspace Settings file (settings.json):

"python.pythonPath": "~/home/python/bin/python"

You can access the settings file in Visual Studio Code using File -> Preferences -> Settings.

like image 33
Flurin Avatar answered Oct 08 '22 20:10

Flurin


Here is explained how you can run Visual Studio Code with Python https://code.visualstudio.com/docs/languages/python

EDIT1:

Windows - Python Virtual Environment And PYTHONPATH with Visual Studio Code: https://www.youtube.com/watch?v=AfvuK7US_9s

EDIT2: Ubuntu - http://dacrook.com/setting-up-python-and-virtual-environments-in-visual-studio-code-on-ubuntu/

like image 1
return Avatar answered Oct 08 '22 19:10

return