1

I have installed Python and written a program in Notepad++. Now when I try to type the Python file name in the Run window, all that I see is a black window opening for a second and then closing.

I cant run the file at all, how can run this file?

Also I want to tell that I also tried to be in the same directory as a particular Python file but no success.

Martin Evans
  • 45,791
  • 17
  • 81
  • 97
Rohail
  • 75
  • 1
  • 11
  • Try to open the program within idle and not as a standalone. Maybe you get get more information on what exactly the problem is – Minzkraut Nov 24 '15 at 09:13
  • 2
    Possible duplicate of [How to keep a Python script output window open?](http://stackoverflow.com/questions/1000900/how-to-keep-a-python-script-output-window-open) – Sam Nov 24 '15 at 09:13

3 Answers3

0

I assume you are running the script with command python file_name.py.

You can prevent closing of the cmd by getting a character from user.

use raw_input() function to get a character (which probably could be an enter).

Vishvajit Pathak
  • 3,351
  • 1
  • 21
  • 16
0

It sounds like you are entering your script name directly into the Windows Run prompt (possibly Windows XP?). This will launch Python in a black command prompt window and run your script. As soon as the script finishes, the command prompt window will automatically close.

You have a number of alternatives:

  1. First manually start a command prompt by just typing cmd in the Run window. From here you can change to the directory you want and run your Python script.

  2. Create a Windows shortcut on the desktop. Right click on the desktop and select New > Shortcut. Here you can enter your script name as python -i script.py, and a name for the shortcut. After finishing, right click on your new shortcut on the desktop and select Properties, you can now specify the folder you want to run the script from. When the script completes, the Python shell will remain open until you exit it.

  3. As you are using Notepad++, you could consider installing the Notepad++ NppExec plugin which would let you run your script inside Notepad++. The output would then be displayed in a console output window inside Notepad++.

  4. As mentioned, you can add something to your script to stop it completing (and automatically closing the window), adding the line raw_input() to the last line in your script will cause the Window to stay open until Enter is pressed.

Martin Evans
  • 45,791
  • 17
  • 81
  • 97
-1

Try to open in Command Prompt instead of run window. The syntax is:

py filename.py

If it doesn't work, try to reconfigure Python. Did you set environment variables? If not, this could help you

Owenz
  • 44
  • 1
  • 8