Python Forum
Python Program Runs in Pycharm but not in Terminal
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Program Runs in Pycharm but not in Terminal
#1
Hi there,

I am 2 days into learning Python (tried a year ago but couldn't continue at that time). So, I am trying to make simple Programs to learn this language and I have written the following program which does very basic of Mathematics. Now, when I run this program in PyCharm I get no error whereas when I am running from a Terminal It's not working as expected.

Another thing is It runs in a Terminal if I copy paste the File in same folder as PyCharm. Here are all the Details:

Code:

num1 = False
num2 = False
operator = True

while type(num1) is not int:
    try:
        num1 = int(input("Enter First Integer: "))
    except ValueError:
        print("Error: Only accepts Integers")
while type(num2) is not int:
    try:
        num2 = int(input("Enter Second Integer: "))
    except ValueError:
        print("Error: Only accepts Integers")

try:
    while operator is True:
        operator = input("Enter an Operator: ")
        if operator == "+":
            result = num1 + num2
            operator = False
        elif operator == "-":
            result = num1 - num2
            operator = False
        elif operator == "*":
            result = num1 * num2
            operator = False
        elif operator == "/":
            result = num1/num2
            operator = False
        else:
            operator = True
            print("Enter a correct Symbol")
    print(result)
except:
    print("Unkown Error")
Snapshot when I run it from Pycharm:
[Image: Khy9fDp]

Snapshot of when I run from Terminal (from a Folder on Desktop)
[Image: sFemgs6]

Snapshot of when I give the Path of Python.exe file of Pycharm Folder and then run the file (It works then):
https://imgur.com/a/UJ39bUL

And it also works if I copy paste the Code File in PyCharm Folder.

I did try changing the PythonPath Home but that didn't fix the issue.

Any guidance on this is appreciated. Thanks !

Regards,
Reply
#2
Hello and welcome to Python and the forums!

For me your code works fine, either in PyCharm, PyCharm terminal or Windows PowerShell.

I recommend you to rewrite your Except clause, so it will display the specific error that happens (instead of just "unknown" message):

except Exception as e:
    print(e)
Reply
#3
Hi,

First of all thank you so much for replying and looking into my problem. I did what you asked but it doesn't help out that much. Please check the following Image. I am running the same program from CMD vs PS and it's giving different results.. Take a look pls and let me know what could be causing this.

[Image: wm84PPJ]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Module which run in PyCharm but not as exe or terminal. diegoctn 3 2,449 Jul-13-2021, 04:03 AM
Last Post: Harshith
  Importing a function from another file runs the old lines also dedesssse 6 232 Jul-06-2021, 07:04 PM
Last Post: deanhystad
  Dynamic Printing With Python Terminal MrTim 2 199 Jul-06-2021, 04:00 PM
Last Post: MrTim
  Running latest Python version on the Terminal (MAC) Damian 4 581 Mar-22-2021, 07:58 AM
Last Post: Damian
  keyboard module doesn't work in the microsoft version terminal of python. username 1 533 Feb-25-2021, 05:19 PM
Last Post: Larz60+
  gnome terminal playing with python jmex 12 957 Feb-03-2021, 01:38 PM
Last Post: Axel_Erfurt
  Refresh data in python script while running in Terminal frankenchrist 4 769 Feb-03-2021, 09:54 AM
Last Post: Larz60+
  how to change the range of read CSV file every time python file runs greenpine 6 763 Dec-08-2020, 10:11 PM
Last Post: greenpine
  read terminal text from running program AArdvark_UK 2 572 Aug-27-2020, 12:43 PM
Last Post: AArdvark_UK
  Runs perfect in Python but fails to print last statement when converted to .exe. Help sunil422 3 732 Aug-13-2020, 01:22 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020