69

I have been using PyCharm for a bit so I am not an expert.

How I normally ran my programs was with the terminal like so:

program.py -t input1 -t1 input2

I was wondering how can I debug this?

For other programs I wrote, I did not have any arguments so debugging was simply setting break points and pressing debug.

Liondancer
  • 15,721
  • 51
  • 149
  • 255

4 Answers4

94

Menu: Run -> Edit configurations -> "+" (add new config) -> Python.

Script name: program.py

If you need to debug a script from installed packages, such as tox, you can specify the full path too. For example: Script name: /home/your_user/.envs/env_name/bin/tox

Above /home/your_user/.envs/env_name is a path to virtual environment containing tox package.

Script params: -t input1 -t1 input2

Andrew_Lvov
  • 4,621
  • 2
  • 25
  • 31
  • You seem to be pretty good at using PyCharm I have another question if you dont mind helping =D http://stackoverflow.com/questions/27952638/usr-bin-env-python3-4-within-pycharm-project – Liondancer Jan 14 '15 at 21:18
  • @DrumM not sure I understand you. Can you clarify and give an example what you're trying to do ? – Andrew_Lvov Feb 04 '18 at 11:49
  • easy: like you would do on a command line, adding variables to it: e.g.: ./program.py $LIST_OF_FILES It's just a pain in the *** if the list of files you want to test, you always have to change the config... – jaques-sam Feb 05 '18 at 22:30
  • @DrumM - there is a tick to open confuguration screen on each launch. That's one option. Option 2: get output of your shell command inside python app you're debugging. Option 3: specify the facilitator as the launch app. It will gather required data and then run the code you're trying to debug – Andrew_Lvov Feb 07 '18 at 10:17
  • 1
    Note that arguments with spaces in them should be wrapper in double quotes, _not single quotes_. This tripped me up for a little bit. – Brady Dowling Jan 02 '19 at 17:23
  • I can't see python and the edit configuration section! – basilisk Jan 14 '20 at 10:54
  • @basilisk What IDE are you using? And what do you see ? – Andrew_Lvov Jan 15 '20 at 10:09
40

Just an image-based representation of the answer.

  1. Click on the Run menu click Edit Configurations...

    enter image description here

  2. Select + in top right corner and select Python

    enter image description here

  3. Provide the name, absolute path of the script or select the script by clicking three dots (green arrow), script parameters, and python interpreter.

    enter image description here

Akaisteph7
  • 5,034
  • 2
  • 20
  • 43
Jebaseelan Ravi
  • 697
  • 8
  • 22
  • In case its not clear, the parameter 1 and parameter 2 are not place holders but actual values. – ijuneja Jan 16 '21 at 06:41
1

It was almost correct but just needed little correction with full script path.

Menu: Run->Edit configurations->"+" (add new config)->Python.

Script name: path + /program.py

Script params: -t input1 -t1 input2

amdev
  • 6,703
  • 6
  • 42
  • 64
ArjunM
  • 11
  • 2
0

I guess PyCharm Community Edition is different or something. Once inside of the configurations, what I had to do was:

  1. Enable Python parameters: modify options -> parameters

  2. Then you can enter your parameters: enter parameters

Akaisteph7
  • 5,034
  • 2
  • 20
  • 43