Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
run .py file on Windows
#1
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!
Reply
#2
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.
Recommended Tutorials:
Reply
#3
(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.
Reply
#4
(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
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#5
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  batch file for running python scipt in Windows shell MaartenRo 2 1,907 Jan-21-2022, 02:36 PM
Last Post: MaartenRo
  Using a .bat file to execute simple anaconda commands in Windows 10 gacg1 0 4,694 Nov-30-2020, 03:24 PM
Last Post: gacg1
  opening a file from a windows desktop folder- error opening file Charan007 1 2,989 Dec-06-2018, 11:50 AM
Last Post: buran
  python 2.7 access denied when writing a file to Windows kavise 2 11,328 Feb-13-2018, 08:30 PM
Last Post: kavise
  Python 3.x Windows 7 registry file associations broken pixhellmann 2 5,076 Sep-12-2017, 09:14 PM
Last Post: Larz60+
  File access confusion python windows PickyBiker 0 3,367 May-08-2017, 05:36 PM
Last Post: PickyBiker
  Get File Ownership under Windows newatpython 6 16,359 Mar-24-2017, 01:18 PM
Last Post: sparkz_alot
  Windows: Put File automatically under Cursor for Drag & Drop sym 1 3,498 Jan-13-2017, 04:55 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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