error running script in python3.7.2 interpreter - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: error running script in python3.7.2 interpreter (/thread-18551.html) |
error running script in python3.7.2 interpreter - srm - May-22-2019 hi there , I am trying to run one of my script file i.e firstfile.py on my windows 2008 r2 machine where in I have installed python3.7.2. While installing I selected "Add to Path" option . my installation path is default i.e C:\Users\Administrator\AppData\Local\Programs\Python\Python37 I have saved my firstfile.py python script file in the same location. When trying to run this file from shell i.e interpreter following error is coming: how to run this file....and tried to save the above python.exe path in system PATH variable also...but still can not run file..Running the same file from cmd(windows console) it is running fine...no issues there... Thanx in advance RE: error running script in python3.7.2 interpreter - buran - May-22-2019 you are trying to run it from python interactive mode (>>> shows you are in interactive mode) this should be executed from command prompt (shell) https://python-forum.io/Thread-How-to-Execute-python-code RE: error running script in python3.7.2 interpreter - snippsat - May-22-2019 As mention you can not do it like this in interactive mode. A couple of advice C:\Users\Administrator\AppData\Local\Programs\Python\Python37 ,i don't like this default path and you should not save your python file there.I give advise here to make your own path shorter Path. Can use any folder as python should be in Windows Path .A little long to type just to run myfirstfile.py python.exe C:\Users\Administrator\AppData\Local\Programs\Python\Python37\myfirstfile.pyExample of running file from own made folder. # myfirstfile.py s = 'Hello World' print(s)Running from cmd or better cmder(then can also jump straight to any folder from file explorer). E:\div_code λ python myfirstfile.py Hello WorldCan start code this in interactive mode with python -i myfirstfile.py .E:\div_code λ ptpython -i myfirstfile.py Hello World # Now can test more on code in interactive mode >>> s.upper() 'HELLO WORLD' >>> s.count('l') 3The combination of ptpython(what i use) or IPython,with cmder make this whole lot better on Windows. RE: error running script in python3.7.2 interpreter - srm - May-23-2019 that means you can not run any *.py i.e script file from python interactive shell(interpreter)which is there when I install IDLE..I just wanted that clarity.... RE: error running script in python3.7.2 interpreter - snippsat - May-23-2019 You run a file in shell bye using exec() or subprocess.Not so common to do this,as in most cases this is not needed. E:\div_code λ ptpython >>> exec(open('myfirstfile.py').read()) Hello World >>> import subprocess >>> subprocess.run(['python', 'myfirstfile.py']) Hello World |