18

I am new to PyCharm and I have 'Process finished with exit code 0' instead of getting (683, 11) as a result (please see attachment), could you guys help me out please? Much appreciate it!

enter image description here

10
  • 2
    Please add your code or output or whatever as text, in the question, not as an image with a generic description hosted on some external site.
    – abarnert
    Mar 24, 2018 at 1:18
  • 2
    Finally, "Process finished with exit code 0" is what PyCharm prints when your program finishes running with no errors. So… what do you want to change about that? Do you want to exit with an error? Or maybe you want to print something out before exiting with no error? Or…?
    – abarnert
    Mar 24, 2018 at 1:20
  • 2
    @abamert, thanks a lot for your help! It's sorted now, a silly rookie mistake:)
    – ET44
    Mar 24, 2018 at 1:34
  • 7
    @abarnet is it really necessary to post three separate comments about the same thing. It is obvious he is pretty new, and still learning about PyCharm. Why not just offer some encouragement, and telling him he is doing the right thing.
    – leogoesger
    Mar 24, 2018 at 1:49
  • 2
    @Enkouyami, what in the existing answer is missing to explain the issue? Jun 19, 2018 at 11:40

10 Answers 10

40

That is good news! It means that there is no error with your code. You have run it right through and there is nothing wrong with it. Pycharm returns 0 when it has found no errors (plus any output you give it) and returns 1 as well as an error message when it encounters errors.

Editors and scripts do not behave like the interactive terminal, when you run a function it does not automatically show the the result. You need to actually tell it to do it yourself.

Generally you just print the results.

If you use print(data.shape) it should return what you expect with the success message Process finished with exit code 0.

5
  • 1
    @user9542899 No problem. Just takes some getting used to
    – Xantium
    Mar 24, 2018 at 1:35
  • How do you get past the exit code? Like if I have an output dataframe that I want to access, but I can't type on a new line in the console becuase it has the exit code output.
    – mikey
    Oct 2, 2020 at 17:39
  • @mikey I'm not quite sure what you mean. Whenever you get an exit output your script has finished executing (or there was an error and it was forced to stop). There is no way to get around this, a value will always be returned as soon as execution has finished. You can use input() to take input, or to pause the script execution. Otherwise it should just be a question of adding the right instructions. If it just stops unexpectedly, then queck your code, either there is an error, or maybe a condition isn't met which causes it to just stop.
    – Xantium
    Oct 4, 2020 at 13:59
  • @mikey Also note that if you run it through a normal terminal (i.e. not pycharm, but through CMD or the default interpreter), execution will just stop (either the terminal will close, or you will get >>>, > or similar to tell you it's waiting for the next command and no return value will be shown.
    – Xantium
    Oct 4, 2020 at 14:01
  • It would be very useful to be able to examine the variables in the code once the program has run. The exit code stops you from being able to do this. This is the difference between running a script and an interactive terminal. So, I think the question is how to ensure how PyCharm runs in the latter?
    – David Kane
    Aug 25, 2021 at 8:32
12
+25

exit code 0 means you code run with no error.

Let's give a error code for example(clearly in the below image): in below code, the variable lst is an empty list, but we get the 5 member in it(which not exists), so the program throws IndexError, and exit 1 which means there is error with the code.

enter image description here

You can also define exit code for analysis, for example:

ERROR_USERNAME, ERROR_PASSWORD, RIGHT_CODE = 683, 11, 0
right_name, right_password = 'xy', 'xy'

name, password = 'xy', 'wrong_password'

if name != right_name:
    exit(ERROR_USERNAME)

if password != right_password:
    exit(ERROR_PASSWORD)

exit(RIGHT_CODE)

enter image description here

3

I would recommend you to read up onexit codes.

exit 0 means no error.

exit 1 means there is some error in your code.

This is not pyCharm or python specific. This is a very common practice in most of the programming languages. Where exit 0 means the successful execution of the program and a non zero exit code indicates an error.

3

What worked for me when this happened was to go to

Run --> Edit Configurations --> Execution --> check the box Run with Python Console (which was unchecked).

2

Almost all the program(C++/python/java..) return 0 if it runs successful.That isn't specific to pycharm or python.

In program there is no need to invoke exit function explicitly when it runs success it invoke exit(0) by default, invoke exit(not_zero_num) when runs failed.

You can also invoke exit function with different code(num) for analysis.

You can also see https://en.wikipedia.org/wiki/Exit_(system_call) for more details.

2

This means that the compilation was successful (no errors). PyCharm and command prompt (Windows OS), terminal (Ubuntu) don't work the same way. PyCharm is an editor and if you want to print something, you explicitly have to write the print statement:

print(whatever_you_want_to_print)

In your case,

print(data.shape)
1

I think there's no problem in your code and you could find your print results (and other outputs) in the tab 5: Debug rather than 4: Run.

1
  • This should be a comment, not an answer
    – Swifty
    Jun 17, 2019 at 16:55
0

I just ran into this, but couldn't even run a simple print('hello world') function.

Turns out Comodo's Firewall was stopping the script from printing. This is a pretty easy fix by deleting Python out of the Settings > Advanced > Script Analysis portion of Comodo.

Good Luck

0

I had same problem with yours. And I finally solve it I see you are trying to run code "Kaggle - BreastCancer.py" but your pycharm try to run "Breast.py" instead of your code. (I think Breast.py only contains functions so pycharm can run without showing any result) Check on tab [Run] which code you are trying to run.

0

Your starting the program's run from a different file than you have open there. In Run (alt+shift+F10), set the python file you would like to run or debug.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.