3

It was my understanding that to add a command line option (in my case I want the -i option) to the python execution in VScode, I was to alter the variable "python.terminal.launchArgs"

As this is curiously not working, I am going to describe the steps I took, so that perhaps some more knowledgeable person can spot my mistake.

  1. I went to file > preferences > settings

  2. then I searched for python

  3. The first mention I found to settings.json was in Python > Analysis:Disabled. I clicked "Edit in settings.json", hoping to open the config file

  4. I set the config file as follows:

    {
    "window.zoomLevel": 3,
    "python.pythonPath": "/usr/bin/python3",
    "python.terminal.launchArgs": ["-i"]
    }
    
  5. I went back to my code and pressed F5 to run it. It ran on the terminal that comes with vscode. The command line was as follows

    lucas@mongolia:~/aulas_ed$ cd /home/lucas/aulas_ed ; env "PYTHONIOENCODING=UTF-8" "PYTHONUNBUFFERED=1" /usr/bin/python3 /home/lucas/.vscode/extensions/ms-python.python-2018.12.1/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 34661 /home/lucas/aulas_ed/teste.py
    
  6. As you can see, that did not include "-i".

  7. I tried altering other variables in settings.json, in the same window. The text size works (text size changes immediately) and the python path variable works (if I type a nonsensical path, F5 stops working and VScode starts complaing about an undefined path -- just to say that the settings file seems to work properly for other ends.

3
  • 2
    Just found this in the Python settings reference in the subsection about python.terminal.launchArgs: "Note that Visual Studio code ignores this setting when debugging because it instead uses arguments from your selected debugging configuration in launch.json." Commented Jan 11, 2019 at 2:53
  • I have just started using VSCode. For a project I have to pass the -s option (whether debug or not) to python else it goes wrong on start-up, but like you cannot find how to do that. Which means I am completely stumped. Any further ideas, or how did you work around? Commented Nov 13, 2019 at 13:13
  • unfortunately i did not find any solution. you can ask a separate question, and hopefully someone will help you Commented Nov 13, 2019 at 13:16

2 Answers 2

0

Found a way... But for sure it's not THE way...

.vscode/settings.json

{
    "python.terminal.launchArgs": [ 
        "${workspaceFolder}/main.py",
        "--port 8010"
    ]
}

pythonfile (main.py)

import sys
port = int(sys.argv[-2].split(' ')[-1]) if int(sys.argv[-2].split(' ')[-1]) else 8001

# >>>  * Running on http://10.100.100.75:8010/ (Press CTRL+C to quit)
Sign up to request clarification or add additional context in comments.

1 Comment

Please add further details to expand on your answer, such as working code or documentation citations.
0

From VSCode Python Debugging documentation, these days we can achieve it by adding a "pythonArgs" entry into the launch.json.

Unfortunately for my situation (where I wanted to specify -m to run as a module, which would've seen me adding "pythonArgs": ["-m"] to the json), this does not seem to work. (My python complained, writing No module named -X to the console, and the VSCode put up an error message saying "Timed out waiting for the debuggee to spawn.") So, your mileage may vary.

Interestingly, for my case of wanting to specify -m, that same documentation mentions that there is actually an easier way. For that special case just replace the "program" entry in the launch.json file with a "module" entry instead. This seemed to work for me at first, in that my python code started running, but then VSCode put up the same error message saying "Timed out waiting for the debuggee to spawn.", at which point my python code suddenly stopped.

Adding this info in case the problems I encountered were local to my setup or use case, and hoping that someone else might try one of these same things and have success.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.