Skip to content

Set up Notepad++ to run Python Script

This is an short guide to set up Notepad++ to run Python script on Windows. First of course you'll need to download and install Notepad++ and Python

Download and install or update Python

When installing Python for the first time checking the box Add Python to PATH at the bottom of the setup screen. This allows you to run programs using the command window. In case of an update, the following screen appears:

Download and install or update Python

To check that your installation is complete press the Windows Key + R on your keyboard in order to open the Run dialog box.

  • Type cmd and click OK.
  • Type where Python and ENTER

Check Python installation path

Install NppExec

To make python work in Notepad++ you need to install a plugin. At the top of the screen, click on Plugins > Plugins Admin... select NppExec and click to install.

From the main menu click on Plugins > NppExec and hoover the submenu. The following options can be set by going through the fist step up several times.

Check the options:

  • Show NppExec Console
  • No internal messages
  • Follow $(CURRENT_DIRECTORY)

Un Check option:

  • Console commands history

I prefer a monospaced font like Lucida Console as a font whose letters and characters each occupy the same amount of horizontal space. You may want to change this too from the main menu for Plugins > NppExec > Change Console Font... and Plugins > NppExec > Change Execute Script Font....

Press the Windows Key + R on your keyboard again. Type cmd and click OK. Type where Python and copy the address path as you will need this for NppExec Plugin.

From the main menu click on Plugins > NppExec > Execute Npp Exec Script... and paste the address followed by "$(FILE_NAME)". This allows you to call any version of Python.

To symplify this you may want to copy following lines. But please note, this assumes that your Environment Variables for are set correctly.

echo ================ START NppExec ========
npp_save
cd $(CURRENT_DIRECTORY)
echo Current File     : $(FILE_NAME)
echo ================ START Python =========
python $(FILE_NAME)

Info

If file names with spaces are used, quotation marks must be set in the Python call python "$(FILE_NAME)"!

Click OK. A box will popup asking you to name the script. Type Run Python and click save.

NppExec Script

From the main menu click on Plugins > NppExec > Advanced Option. Check Place to the Macros Submenu and in the dropdown menu under Associated Script select the script that you just have created. Click Add/Modify

Notepad++ must be restarted to apply some of the options.

NppExec Advanced Options

Restart Notepad++ by closing and then opening the window. Now write some lines of code to test and save the file. You can select the file extension from the dropdown menu or type .py after your file name. Click OK.

In Notepad++ From the main menu click on Macro > Run Python and you will get the printout of the code in the lower part of the window.

Run Python

Make a shortcut to run the script.

From the main menu click on Settings > Shortcut Mapper... and scroll down to find Run Python (Tip: View right column NppExcel.dll) and double click to select it. Select Ctrl + F9, click OK and Close.

Notepad++ Shortcut Mapper

To see this in action, close the Shortcut Mapper window in notepad++ and click CTRL + F9 together.