Python Forum

Full Version: run .py file on Windows
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, so I just installed python and I wanted to test the program and stuff. so I made a simple test file, hello.py which has its own folder on my desktop "print("Hello")". My Python was installed automatically (didn't know how to change directory during installation) here : C:\Users\username\AppData\Local\Programs\Python\Python36-32

and i ticked the box which said to add to PATH. running the interpreter is fine. everything seems good to go.

I gather that to run the file in the command line I should just : hello.py or something which I did. I tried C:\Users\username > hello.py

C:\Users\username > python hello.py

C:\Users\username > python
then the python interpreter then hello.py

obviously its not working, as in error of no file name or something along those lines, because of the file directory bit. so where should i place the .py file? or is there something completely wrong with the setup altogether? Thanks in advance!
Quote:
C:\Users\username > python hello.py
This is the correct method. You should either get an error message or the script hello.py runs.

adding to the PATH should fix this; but you can try troubleshooting by putting the file hello.py in the directory C:\Users\username\AppData\Local\Programs\Python\Python36-32

I havent used Windows in an eternity so i forgot how they do it.
(Sep-14-2017, 01:17 PM)aidanikuz Wrote: [ -> ]My Python was installed automatically (didn't know how to change directory during installation) here : C:\Users\username\AppData\Local\Programs\Python\Python36-32
You can look at this for a better path Python 3.6 and pip installation under Windows, part-2.
(Sep-14-2017, 01:17 PM)aidanikuz Wrote: [ -> ]so where should i place the .py file?
It's up to as long as python are in environment variable Path.
Make a folder eg C:\my_py where you can have most of your files.
(Sep-14-2017, 01:17 PM)aidanikuz Wrote: [ -> ]so I made a simple test file, hello.py which has its own folder on my desktop "print("Hello")".

You didn't say what the  folder name was on your desktop, so we'll just call it 'folder'. From the command prompt you need to change directory to that directory.
cd C:\Users\your_name\Desktop\folder
From there, you can just type "hello.py".

To save yourself some typing, you could create a directory under the main "C" directory, call it, say "Python", the you just have to type cd c:\python
(Sep-14-2017, 02:35 PM)sparkz_alot Wrote: [ -> ]
(Sep-14-2017, 01:17 PM)aidanikuz Wrote: [ -> ]so I made a simple test file, hello.py which has its own folder on my desktop "print("Hello")".

You didn't say what the  folder name was on your desktop, so we'll just call it 'folder'. From the command prompt you need to change directory to that directory.
cd C:\Users\your_name\Desktop\folder
From there, you can just type "hello.py".

To save yourself some typing, you could create a directory under the main "C" directory, call it, say "Python", the you just have to type cd c:\python


Thank you. did just that.