Python Forum
error running script in python3.7.2 interpreter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
error running script in python3.7.2 interpreter
#1
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:
Error:
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> python.exe C:\Users\Administrator\AppData\Local\Programs\Python\Python37\myf irstfile.py File "<stdin>", line 1 python.exe C:\Users\Administrator\AppData\Local\Programs\Python\Python37\myf irstfile.py ^ SyntaxError: invalid syntax
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
Reply
#2
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-Ex...ython-code
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
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.py
Example 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 World
Can 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')
3
The combination of ptpython(what i use) or IPython,with cmder make this whole lot better on Windows.
Reply
#4
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....
Reply
#5
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Running script from remote to server invisiblemind 4 749 Mar-28-2025, 07:57 AM
Last Post: buran
  Detect if another copy of a script is running from within the script gw1500se 4 1,138 Jan-31-2025, 11:30 PM
Last Post: Skaperen
  Pandas - error when running Pycharm, but works on cmd line zxcv101 2 2,453 Sep-09-2024, 08:03 AM
Last Post: pinkang
  No Internet connection when running a Python script basil_555 8 3,327 Mar-11-2024, 11:02 AM
Last Post: snippsat
Question Running Python script through Task Scheduler? Winfried 8 6,751 Mar-10-2024, 07:24 PM
Last Post: Winfried
  Help Running Python Script in Mac OS emojistickers 0 960 Nov-20-2023, 01:58 PM
Last Post: emojistickers
  error "cannot identify image file" part way through running hatflyer 0 2,011 Nov-02-2023, 11:45 PM
Last Post: hatflyer
  Trying to make a board with turtle, nothing happens when running script Quascia 3 1,776 Nov-01-2023, 03:11 PM
Last Post: deanhystad
  Kivy App - Python3 script to Android app (opencv) jttolleson 7 8,074 Oct-19-2023, 01:11 PM
Last Post: MasCain
Sad Migrating of python2 script to python3 zuri 7 4,304 Oct-05-2023, 02:40 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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