1

Every time I run a Python script, the cmd window appears and then immediately closes. I can't even get the basic "hello python" to run.

I'm on a Windows seven machine and Python is installed to:

C:\Users\Chaos\AppData\Local\Programs\Python\Python35-32\python.exe

The test script is

C:\Users\Chaos\AppData\Local\Programs\Python\Python35-32\python.exe
print ("Hello, Python!")
raw_input()

Anyone have a clue whats happening here?

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
Justin Jacoby
  • 11
  • 1
  • 1
  • 3

4 Answers4

2

First you should validate that Python is installed. You said it was installed here for your machine: C:\Users\Chaos\AppData\Local\Programs\Python\Python35-32\python.exe

You should double check that Python is in your system environment variables. This varies by version of windows but you essentially want to:

  1. go to control panel
  2. go to system
  3. go to advanced system settings
  4. click on environment variables
  5. Click on new or add and then add the path to the folder containing the python executable, so add this: C:\Users\Chaos\AppData\Local\Programs\Python\Python35-32\

Now launch cmd.exe and type in 'python' without the quotes and you should see the REPL launch. If the REPL doesn't launch you know you have an installation issue or didn't properly setup the environment variable. If the REPL does launch then you should be able to launch your python script from the command line:

python -m yourHelloWorld.py

Please note that you need to prove an absolute path to your file if it's not in the current working directory that you're trying to launch from, or you need to navigate to that directory.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Kevin S
  • 930
  • 10
  • 19
0

try write this comment on first line in your python file: # -*- coding: utf-8 -*-

sorry for my bad English.

SunTechnique
  • 185
  • 2
  • 4
0

This should work:

py script.py

Or even

script.py

When the window just closes like that, the script likely crashed.

If it doesn't, you might actually have an empty/stale copy of script.py in the current folder, try making sure that the script filename you're specifying is indeed the one you want to run.

To debug this try providing a full path to py

py "C:\Users\me\Desktop\Script.py"
bobobobo
  • 64,917
  • 62
  • 258
  • 363
0

There are two problems with your code itself. I am not so sure about naming the file and adding python to PATH and that sort of stuff but I can see 2 problems in the code.

The first problem is the space between the print and where the brackets start. This is what it should look like:

print("Hello world!")

The second problem is using raw_input() instead of input() this is what that should look like:

input()

So your overall code should be this:

print("Hello world!")
input()
Ram
  • 43
  • 7