0

I am working on page 16, chapter 1, in the book "Python Crash Course" by Eric Matthes. I am trying to run my hello_world.py python program from my Windows terminal. The directions say to:

Open a new terminal window and issue the following commands to run hello_world.py:

C:\> **cd Desktop\python_work**

C:\Desktop\python_work> **dir**
hello_world.py

C:\Desktop\python_work> **python hello_world.py**

Hello Python world!

python_work is my python work folder on my desktop. In my Windows terminal, I have tried entering the code with and without the unbolded C:\>. It has given me an error message: The system cannot find the path specified. I'm probably doing something wrong, but I don't know what's wrong.

Dom
  • 1,687
  • 6
  • 27
  • 37
K. Krieger
  • 1
  • 1
  • 2

3 Answers3

0

Assuming your getting your error when you execute "python hello_world.py", Python might not be installed correctly. More likely is that you are not in the correct directory. Do the following commands:

cd "C:\Desktop\python_work"
python hello_world.py

If that does not work, I can only assume one of two things: Either the folder or the .py file is not named what you think it is and you should rename whichever one, or python is not installed correctly and you should reinstall it.

jalomas7
  • 382
  • 4
  • 5
  • I'm sure Python was installed correctly because I followed the exact instructions in the book. I also know that my python folder is on my desktop and all files are named correctly. Should I enter the code you showed me after I type in "python" when I first open the terminal? – K. Krieger Jan 28 '16 at 03:31
  • no. see the terminal can only access files, programs, folders, etc. from either a "relative directory" or from the "working directory", the `cd "C:\Desktop\python_work"` command makes "C:\Desktop\python_work" the working directory of the terminal. Only when the correct directory is your working directory will (or should) `python hello_world.py` work – jalomas7 Jan 29 '16 at 01:25
0

use

cd C:\Desktop\python_work

to change your working directory and then type

hello_world.py

to launch your program or if that doesn't work try

python hello_world.py

alternatively (what I do), assuming the first option worked, you can create a .bat file with the following code.

@echo off
"%~dp0\hello_world.py" %*
pause

and then just put that bat file in the same folder as "hello_world.py" and when you run the bat file it will launch the script. :)

Dustin Nunyo
  • 96
  • 1
  • 9
0

With mouse right click on saved file and choose properties to watch the file path. Then in windows terminal write : cd file path Then dir then python hello_world.py.