running python in cmd on win10 - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: running python in cmd on win10 (/thread-26897.html) |
running python in cmd on win10 - rny1python - May-17-2020 folks, embarrassing, but nonetheless stuck. i am in Corey Shafer's Beginner's Tutorial #1 and just installed python 3.8.3. python installed into c:\users\ron\appdata... and i added a path to c:\python\python38-32 i ran python, used idle, and created an 'hello world' stored as c:users\ron\desktop\intro.py when i type python desktop\intro.py i get a syntax message [i tried every variation i could think: - c:\users\ron\desktop> python intro.py invalid syntax - c:\>python> c:\users\ron\desktop\intro.py invalid syntax if i use either of the basic setups, and type just python, i do get the >>> and can do a simple print ('hello world). so, what embarrassing tidbit am i missing with this syntax stuff? i can go to windows, launch python, open idle and find the file, but i can't execute it [in the Beginner's Tutorial, Corey executes it from a MAC, but i can't get it to work in the cmd prompt can someone enlighten me? thanks, ron RE: running python in cmd on win10 - snippsat - May-17-2020 (May-17-2020, 08:46 PM)rny1python Wrote: when i type python desktop\intro.py i get a syntax message [i tried every variation i could think:Look at this. You are in interact shell( >>> ) when run python desktop\intro.py this need to be done from cmd.Make sure that python and pip work from command line(cmd ) as shown in link over,before doing anything elseFor running code in IDLE,so not using >>> that it start up in bye default.To get started is PyScripter very easy to use. After while look into VS Code from start. RE: running python in cmd on win10 - rny1python - May-18-2020 snipssat, ok, this is great. i uninstalled everything, started fresh and followed the python install from your first line ...Look at this... did the set path option, put python into c:\program files (x86) tried the >>> print ('hello world') and it worked. then went to the windows, found the new app Python 3.8, clicked on IDLE: 0. this brought up the python shell 1. did a file\open to open intro.py saved on the desktop 2. that brought up intro.py - C:\Users\ron\Desktop\intro.py (3.8.3) 3. that gave me >>> print ('hello world') 4. did a run module 5. and got 'invalid syntax' very clearly something quite simple is escaping me [maybe that is why i am still sitting with Beginners Tutorial #1 after 2 days] anyway, progress has been made. if you have the patience, can you help? this 'syntax error' from IDLE i suspect is the same 'syntax error' i get when i go into cmd and do this, yes? cmd c:\users\ron\desktop>python \intro.py thanks, ron RE: running python in cmd on win10 - snippsat - May-18-2020 Point 2 intro.py when you save to any .py file.There should not be any >>> in code,look at this image again. rny1python Wrote:cmdDesktop is not the best place to store you python files. Make a own folder eg C:\code .rny1python Wrote:python \intro.pyNo \ when run code.Here is from start in cmd to run intro.py on Desktop.# intro.py print('hello world')Start cmd :Microsoft Windows [Version 10.0.18362.836] (c) 2019 Microsoft Corporation. Med enerett. C:\Windows\System32>cd\ # cd to desktop C:\>cd c:\users\tom\desktop # Test python c:\Users\Tom\Desktop>python -V Python 3.7.3 # Test pip c:\Users\Tom\Desktop>pip -V pip 20.0.2 from c:\python37\lib\site-packages\pip (python 3.7) # Run intro.py c:\Users\Tom\Desktop>python intro.py hello world c:\Users\Tom\Desktop>As mention PyScripter is an easy way to get started. Here a older image when used Python 2,it work just the same today with python 3. I do many of my quick code testing in PyScripter as can just copy/paste from forum and push run,there is even no need to save the file. RE: running python in cmd on win10 - deanhystad - May-18-2020 Does your intro.py file have '>>>' in it? If so, please delete that and try running again.'>>>' is the python prompt. If your program text is ">>> print('Hello world')" you will get a "syntax error" because python does not understand what ">>>" means. RE: running python in cmd on win10 - rny1python - May-18-2020 snipssat & deanhystad, ok, i think 'grasshopper' [odd, since i am 73] has finally found the end of the string. i was doing multiple things wrong. so, did all the installs over as i said before. using snipssat ...There should not be any >>> in code,look at this image again.... - i executed as in the image, and it worked then i took dean's point, hammered multiple times by snip but didn't register, and typed this into cmd: - c:\>python c:\users\ron\desktop\intro.py and it worked to recap for understanding so i created a file the first time in the shell (the 'shell' is actually IDLE, yes?), then went back and tried to run it within cmd under python as follows: - c:\users\ron\desktop>python intro.py this got a syntax error on the 'intro.py'; why(?)because there was no indicated path to intro.py? and if i did this under the shell: - >>>python intro this got a syntax error because i was already in the shell, calling python and it was already there, and what(?), there was no indicated path to intro.py? i'm almost there. i can muddle through i think; i need to sleep on it a tad to understand the process more clearly. but never would have got this far without your help guys. thanks, ron [i was taking some beginner tutorials, covered both mac and windows, but the trainer always went back to the mac and somehow i lost the true 'path' in trying to mimic the mac in cmd. BAD IDEA for me) RE: running python in cmd on win10 - deanhystad - May-18-2020 You are only going to be stupid about Python for a short period of time. Then you'll have to go find something else to be stupid about. Right now I am feeling stupid about Numpy and Matplotlib. |