21

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:

enter image description here

Is there any special configuration needed for debugging in pycharm? Here is my configuration:

enter image description here

Lie Ryan
  • 62,238
  • 13
  • 100
  • 144
hakunami
  • 2,351
  • 4
  • 31
  • 50

4 Answers4

14

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:
enter image description here

Choose the file you want to configure, then click "Edit Configurations":
enter image description here

Add script parameters:
enter image description here

laike9m
  • 18,344
  • 20
  • 107
  • 140
  • Cheers. Looks like we can put multiple variables into the `Script parameters` box with a space as a delimiter and these values will be passed to `sys.argv` when you debug or run the script. – Kouichi C. Nakamura Apr 15 '15 at 05:11
  • Could you take a look at [this](http://stackoverflow.com/questions/34383281/module-not-found-when-debugging)? – Stefan Falk Dec 20 '15 at 17:18
10

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()
BluesRockAddict
  • 15,525
  • 3
  • 37
  • 35
  • 1
    I did what you said but still can't debug. I update this question with more information. Please help me. – hakunami Apr 20 '12 at 04:23
  • Try 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. – BluesRockAddict Apr 20 '12 at 04:32
  • I can debug this helloworld. Actually I put my python file into a new project and every thing works fine. weird? – hakunami Apr 20 '12 at 05:22
  • Any idea how to solve [this](http://stackoverflow.com/questions/34383281/module-not-found-when-debugging) ? – Stefan Falk Dec 20 '15 at 17:18
0

Simply from the context menu by clicking on a needed tab, link https://www.jetbrains.com/help/pycharm/starting-the-debugger-session.html

It will launch debug session in the background, like

/usr/local/bin/python3.7 "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py" --cmd-line --multiproc --qt-support=auto --client 127.0.0.1 --port 56411 --file /Users/proskuryakovivan/code/audio/test.py
Ivan Proskuryakov
  • 1,625
  • 2
  • 23
  • 32
-1

I had similar problem in the past when trying to debug with pycharm. The solution was to start the debuging anywhere (first break point) in the file containing the following code:

def main():
    <your code>

if __name__ == "__main__":
    main()
Pyrce
  • 8,296
  • 3
  • 31
  • 46