I use debugger for Python in Visual Studio Code. It works great, but in many cases I want to debug scripts which use different CLI arguments. It's very cumbersome to create an entry in lauch.json for each CLI argument group I want to debug.
I'm looking for a way for VSC to ask for CLI arguments which will be passed to the script hen debugger starts. I would be even better is there would be some history of previous arguments.
PS. I know you can attach the debugger and run it via the command line, but I hope there is a clean solution :)
About your question:
I'm looking for a way for VSC to ask for CLI arguments which will be passed to the script hen debugger starts.
I'm sorry to tell you that the request can't be met. For now, there're two ways to debug showed in python-debug:
Add configurations in the launch.json, then press Run->Start Debugging, which will create a debug process automatically that provided by the python extension. During this debug process, all debug configurations depend on the content in launch.json:
Command line debugging. The debugger command line syntax you can refer to commandline-debug. Compared to changing configurations in launch.json every time, this is more convenient.
More information about debug in VS Code, please refer to Debugging
Related
When I tried to debug some Deep Learning projects, I noticed that there are many projects use the shell script as the method of passing parameters. We can easily run these projects by bash run.sh in command line, but how to debug these kind of projects in IDEs like Pycharm?
I have tried to use some methods of python to call system commands like: os.system('bash run.sh') in debugger.py and simply debug the debugger.py. But the breakpoint set by pycharm in this method do not work, and will be directly ignored. What is the reason?
I also try to parse the passed parameters in the shell script and add these parameters in the debug configuration of pycharm like this:
debug configuration
but it seems too troublesome, especially when the incoming parameters are complex.
Is there any elegant solution to debug a python project with shell script as the entry?
Or is it not normative to write too complex parameter processing flow in shell script?
very basic one here. I wrote some Python code that worked fine, then used VS Code for SQL work.
Now I want to reuse Python and try as I might I can't get it to Run without first Debugging in PLSQL Debug. Even if I choose Run -> Run Without Debugging the terminal doesn't load the results of the Python script. Instead I get in the Debug Console:
"Debug started on port 4000, waiting on the client to connect..."
I am sure there is a straightforward answer to this, but how do I get back to VS Code treating my Python code like Python code? Thanks!
Your configurations have been changed when you first run PLSQL debug. Go to your main project path find the .vscode folder and delete launch.json.
After you deleted launch.json file, go to Run and Debug and start a new python debug mode
You can select the debug file type in Run and Debug.
I often use the python breakpoint() command as a way of debugging code or for changing the values of variable on-the-fly. This works great when I launch a python script from the (windows) console, as breakpoint() lets me type commands in that console.
My question is how do I do achieve something similar when running a python script launched some other way? For example, when I package my code into an .exe with PyInstaller (with the no-console option to keep it tidy) and launch the .exe, breakpoint() does nothing at all. I know one way to remove this problem is to compile the .exe without the no-console option, but I'd rather have it there as it just keeps everything clean. A similar problem also arises when running a python script via a os.execl() call in another.
Is there someway of making the code launch its own console whenever breakpoint() is called, and having that console control the debugging commands? I suspect that this is possible through manipulating the PYTHONBREAKPOINT variable, but I don't know how, or where to start looking.
This question is very similar to this one but for PyCharm.
I need to use aws-vault to access AWS resources in my script, but this seems to be impossible to accomplish in PyCharm debugging mode. It gives ability to enter script path, parameters, environment variables and there is also external tools functionality, but neither of these work.
Here is the format that works in shell:
aws-vault exec ${AWS_PROFILE} -- script.py
I thought that I've almost arrived at a solution by using external tools and setting the program to "aws-vault" and its arguments to "exec your-profile -- $FilePath$", but it wants to run the script in $FilePath$, finish and only after completion run the debugged script in PyCharm (which is the same one as the one inserted by $FilePath$).
How it would work for my case is by running needed script in debug mode in conjunction with external tool, so the script would go into arguments of the external tool and run as one command.
There are ways to deal with this by launching PyCharm from command line with aws-vault as a prefix or editing its .desktop file and writing the prefix directly into the Exec field, but the app needs to be restarted when AWS profile has to be changed.
Any ideas would be appreciated, thanks.
I was able to do this by installing the envfile plugin in PyCharm. This plugin can read in a .env file when starting a process. Basically I did the following:
Create a script that generates a .env file, envfile.env and name the script generate.sh
This generate.sh script is a shell script that basically does: aws-vault exec $AWS_PROFILE -- env | grep AWS_ > envfile.env, so all the aws creds are in the envfile.env. Possibly add other environment variables if you need so.
Execute command above at least once.
Install the envfile plugin in pycharm.
In the Run configuration, a new tab appears with 'EnvFile'. In this tab, enable the EnvFile. Add the generated envfile.env (see previous).
Do Tool / External Tools and create an external tool for the generate.sh. This way you can execute the script from PyCharm.
Again in the Run configuration add a Before Launch that executes the External Tool generate.sh.
Warning, the temporary aws-creds are in the plaintext envfile.env.
In PyCharm (I assume other IDE's as well), when I press "run" in the taskbar, there are two options:
Run (Shift f10)
Run... (Alt Shift f10)
What is the difference between these two? I could not find this online.
ps. Is this the correct stackexchange site for this question? I didn't know which one fit best.
Shift+Alt+F10 - Quickly select run/debug configuration and run/edit it.
Shift+F10 - Run application.
This information is from: PyCharm 2018.3 Help
But the question is totally and completely not about data-science.
In IntelliJ-based IDEs (and PyCharm is one of them):
Run will run the last run command you executed successfully, be this an invocation of main or a test, or whatever PyCharm executed on your behalf.
Run... will allow you to select a previously run command or previously configured command to run (see Edit Configurations) without it necessarily being the last thing you ran.
Note that this is distinct and separate from debugging. Both debug commands have the same convention as the Run commands, and both do effectively the same thing with the difference in being that the debugger will be attached in a debug context.