HOW TO use Pycharm to debug python script?
Solution 1
Take a look at Run -> Edit Configuration dialog where you should click on Add New Configuration ([+] icon at the left top corner). Then you need to choose project type (probably Python in your case), specify your script (.py) file, parameters, Python interpreter to use etc. Once configuration is selected, you should be able to just run your application in debugger.
Refer to Debugging section in on-line help for more information.
HelloWorld code:
def main():
print "Hello World"
if __name__ == "__main__":
main()
Solution 2
I'd like to illustrate how to set parameters, as it took me a while to do this right:
Find the drop-down menu next to the "Run" button:
Choose the file you want to configure, then click "Edit Configurations":
Add script parameters:
hakunami
Updated on July 09, 2022Comments
-
hakunami almost 2 years
I'm trying to use pycharm. I can write code and run it. However, I do not know how to to debug the code. When I click the debug button, I get something similar to the below image:
Is there any special configuration needed for debugging in pycharm? Here is my configuration:
-
hakunami about 12 yearsI did what you said but still can't debug. I update this question with more information. Please help me.
-
BluesRockAddict about 12 yearsTry creating a simple HelloWorld project with single main.py file. Use the sample code from my answer and put the breakpoint on the second line (print "Hello World"). Create debug configuration for it as type Python and try running it in debugger, you should see debugger stopping at the breakpoint. I just tried it in PyCharm 2.5 and it work fine.
-
hakunami about 12 yearsI can debug this helloworld. Actually I put my python file into a new project and every thing works fine. weird?
-
Kouichi C. Nakamura about 9 yearsCheers. Looks like we can put multiple variables into the
Script parameters
box with a space as a delimiter and these values will be passed tosys.argv
when you debug or run the script. -
Stefan Falk over 8 yearsAny idea how to solve this ?
-
Stefan Falk over 8 yearsCould you take a look at this?