How to execute Python file in Notepad ++?

I prefer to use Notepad ++ for development,

How to execute files in Python via Notepad ++?

+111
python notepad ++
Nov 09 '09 at 17:41
source share
15 answers

The first option: (The easiest, recommended)

Open Notepad ++. In the menu, go to: Run → Run .. (F5). Enter:

 C:\Python26\python.exe "$ (FULL_CURRENT_PATH)" > 

Now, instead of clicking on the mileage, click "Save" to create a shortcut for it.

Notes

  • If you have Python 3.1: type Python31 instead of Python26
  • Add -i if you want the command window to remain open after the script completes



Second option

Use a script package that runs a Python script, and then create a shortcut to it from Notepad ++.

As explained here: http: // it-ride. blogspot.com/2009/08/notepad-and-python.html




Third option: (unsafe)

The code is opened by "HKEY_CURRENT_USER \ Software \ Python \ PythonCore", if the key exists, it will get the path from the first child key of this key.

Check if this key exists, and if not, you can try to create it.

+135
Nov 09 '09 at 17:44
source share

@ Ramiz Uddin's answer definitely deserves more clarity:

  • Open Notepad ++
  • From the menu, go to: Run → Run .. (F5)
  • Enter cmd /K python "$(FULL_CURRENT_PATH)"
+35
Feb 24 '14 at 15:18
source share

Here is what worked for me:

Open Notepad ++ and press F5. You will get a small popup:

Pop-up window to enter the program to run

Type: C: \ Python27 \ python.exe -i "$ (FULL_CURRENT_PATH)" for Python 2.7.

and then Save As ... and select your own keyboard shortcut to launch it every time you want to run something

+19
Nov 20 '14 at 11:44
source share

Install Python first from https://www.python.org/downloads/

Run the installer

** IMPORTANT ** Be sure to check both options:

  • Install launcher for all users
  • Add Python 3.6 to the path

Click Install Now and complete the installation.

Open Notepad ++ and install the PyNPP plugin from the Plugin Manager module . I am using N ++ 6.9.2

Save the new file as new.py

Type in N ++

 import sys print("Hello from Python!") print("Your Python version is: " + sys.version) 

Press Alt + Shift + F5

Just like that.

+12
Jun 18 '16 at 14:03
source share

From the menu, select "Run" → "Run ..." (or just press F5 ).

For Python 2, enter:

 py -2 -i "$(FULL_CURRENT_PATH)" 

For Python 3, type:

 py -3 -i "$(FULL_CURRENT_PATH)" 

Literature:

To better understand the py command:

 py -h 

Another useful link for understanding the py command: How to run python 2 and 3 on Windows 7?

Thanks Repeat for your answer , which got me on the right track to figure it out.

+10
Jan 30 '18 at 18:27
source share

All answers for the Run-> Run option go with the "/ K" cmd switch, so the terminal remains open or "-i" for python.exe, so python forces the interactive mode - like to save for observation.

However, in cmd /k you need to type exit to close it, in python -i - quit() . If it prints too much for your liking (for me it is mandatory :), the Run command to use is

 cmd /k C:\Python27\python.exe "$(FULL_CURRENT_PATH)" & pause & exit 

C:\Python27\python.exe is obviously the full path to your python installation (or just python if you want to go with the first executable in your user path).

& - unconditional execution of the next command in Windows - unconditional, since it is executed independently of the RC of the previous command ( && is "and" - is executed only if the previous completed successfully, || - "or").

pause - prints "Press any key to continue ...". and waits for any key (if necessary, the output can be suppressed).

exit - well, enter exit for you :)

So, at the end, cmd starts python.exe , which executes the current file and saves the open window, pause waits for you to press any key, and exit , finally close the window as soon as you press that any key.

+6
Nov 08 '17 at 16:44
source share

I am using the NPP_Exec plugin (found in the plugin manager). Once this is installed, open a console window (ctrl + ~) and enter:

 cmd 

This will launch the command prompt. Then enter:

 C:\Program Files\Notepad++> **python "$(FULL_CURRENT_PATH)"** 

to execute the current file you are working with.

+5
Apr 26 2018-12-12T00:
source share

None of the solutions suggested earlier worked for me. A slight modification is required.

After pressing F5 in Notepad ++, type:

 cmd /k "C:\Python27\python.exe $(FULL_CURRENT_PATH)" 

The command line remains open, so you can see the output of your script.

+5
Apr 30 '14 at 14:38
source share

I want people here to post steps instead of general concepts. In the end, I got the cmd / k version.

Step by step instructions:

  • At the NPP, click on the menu item: Run
  • In the submenu, click "Run"
  • In the "Run ..." dialog box, in the "Run program" field, delete any existing text and enter: cmd / K "$ (FULL_CURRENT_PATH)" The / K parameter is optional, it saves the open window created when the script was run, if you want to.
  • Click the "Save ..." button.
  • The Shortcut dialog box opens; fill it out if you need a key combination (there is an inscription “It will turn off the accelerator”, whatever that is, so maybe you don’t want to use a key combination, although it probably doesn’t hurt to assign it when you do not need an accelerator) . Somewhere I think you need to tell the atomic power station where the Python.exe file is located (for example, for me: C: \ Python33 \ python.exe). I don’t know where and how you do it, but trying to find different things here, I was able to do it - I don’t remember what attempt did the trick.
+4
Jun 10 '14 at 14:14
source share

There is no answer here, or the plugin I found provided what I wanted. I wrote a minimalist method for running my Python code in Notepad ++ with a click of a shortcut, preferably with plugins.

I have Python 3.6 (64-bit), for Windows 8.1 x86_64 and Notepad ++ 32bit. After you write a Python script in Notepad ++ and save it, press F5 to Run . Then write:

 "C:\Path\to\Python\python.exe" -i "$(FULL_CURRENT_PATH)" 

and click "Run." The i flag causes the terminal to remain stationary after the code completes so you can inspect it. This command will run the script in the cmd terminal, and the terminal will still remain there until you close it by typing exit() .

You can save this for convenience as a convenience (my CTRL + SHIFT + P).

+3
Feb 01 '17 at 17:52
source share

There is one problem that I have not seen in the above solutions. Python sets the current working directory wherever you start the interpreter. If you need the current working directory in the same directory in which you saved the file, you can press F5 and type this:

 cmd /K cd "$(CURRENT_DIRECTORY)"&C:\Users\username\Python36-32\python.exe -i "$(FULL_CURRENT_PATH)" 

Except that you replaced C: \ Users \ username \ Python36-32 \ python.exe with the path to the python interpreter located on your computer.

Basically you run the command line, change the directory to the directory containing the .py file that you are trying to run, and then run it. You can combine as many command line commands as you like with the & character.

+2
Feb 27 '17 at 15:43
source share

Extension Repeat Response

  • Open Run → Run ... from the menu in Notepad ++ (shortcut: F5 )

  • In this space, enter:

     "$(FULL_CURRENT_PATH)" -1 
  • Click Run

ta da!

+1
Nov 04 '17 at 6:14
source share

I started using Notepad ++ for Python just recently, and I found this method very simple. When you are ready to run the code, right-click on the tab of your code in the Notepad ++ window and select "Open Containing Folder in cmd". This will open the Command Prompt in the folder where the current program is stored. All you have to do is execute:

python

This was done on Notepad ++ (Build 10 Jan 2015).

I can’t add screenshots, so here's a blog post with screenshots - http://coder-decoder.blogspot.in/2015/03/using-notepad-in-windows-to-edit-and.html

0
Mar 03 '15 at 6:03
source share

In Notepad ++, go to Run → Run ... , select the path and idle.py file of your Python installation:

 C:\Python27\Lib\idlelib\idle.py 

add a space and this:

 "$(FULL_CURRENT_PATH)" 

and here you are!

Video Help:

https://www.youtube.com/watch?v=sJipYE1JT38

0
Jun 03 '15 at 18:02
source share

Got it to work simply. Using the name "python" rather than the full directory. Now I can read Stack Traces and errors in my program

This works just fine: Cmd / k python "$ (FULL_CURRENT_PATH)"

-python is already on my way - there is no need to use the full path ("c: /python27/python.exe") Although this will work, it will make it difficult to read Stack traces and types of errors in my program.

-2
Oct 26 '14 at 12:21
source share



All Articles