5

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.

Sharath
  • 2,348
  • 8
  • 45
  • 81
  • 1
    Not an answer to your question but Scrapy has some interactive debugging functionality that may be useful for you. – VMRuiz May 03 '17 at 10:44
  • @VMRuiz scrapy i can somehow manage but checking with the virtualenv concept – Sharath May 03 '17 at 10:49
  • Possible duplicate of [Use Virtualenv with Python with Visual Studio Code in Ubuntu](https://stackoverflow.com/questions/37642045/use-virtualenv-with-python-with-visual-studio-code-in-ubuntu) – holms Mar 16 '18 at 15:42

3 Answers3

2

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

holms
  • 9,112
  • 14
  • 65
  • 95
Mr.Van
  • 36
  • 3
  • but how to be in the environment. I have updated the question – Sharath May 03 '17 at 11:03
  • Welcome to SO. Please read this [how-to-answer](http://stackoverflow.com/help/how-to-answer) to follow the SO guidelines to provide a quality answer.. – thewaywewere May 03 '17 at 14:04
  • Check this answer: https://stackoverflow.com/questions/37642045/use-virtualenv-with-python-with-visual-studio-code-in-ubuntu as this represents 2018 – holms Mar 16 '18 at 15:59
2

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.

Flurin
  • 681
  • 5
  • 14
1

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/

return
  • 291
  • 1
  • 13