How do you run a python script from within notepad++?

88,960

Solution 1

Plugins NppExec Execute (F6) is much more powerful than plain Run (F5). Install NppExec via Plugins, Plugin Manager. Then in F6 add/save the following:

NPP_SAVE
cd "$(FULL_CURRENT_PATH)"
C:\Python34\python.exe -u "$(FULL_CURRENT_PATH)"

In Plugins NppExec Console output filters (Shift+F6) add the following HighLight mask:

*File "%FILE%", line %LINE%

Make sure it's checked, and make it e.g. red and underlined.

Upon "F6/execute" errors will be highlighted and clickable !

This works in NPP568, possibly older.

Solution 2

You need to pass through the FULL_CURRENT_PATH environment variable to the program, as described in the notepad++ wiki:

python "$(FULL_CURRENT_PATH)"

Solution 3

You can use PyNPP Plugin (https://github.com/mpcabd/PyNPP) to achieve this.

I know this is old but the answer is for people coming from search.

Solution 4

possible to use pdb too

The answers above were very useful to get it working. However, once i could run the python programs, I also needed to interact with them. Two things I found out.

  1. Use "python -u -i $(FULL_CURRENT_PATH)" if you wish to interact with your program (like giving command line inputs).
  2. to use the awsome PDB, use "python -u -m pdb $(FULL_CURRENT_PATH)" and then you can easily debug your programs as well. :-) loving it!!

Solution 5

if u have the NppExec plugin (is by default) hit F6 and add the command that exec your script

python /path/to/script.py
Share:
88,960
Admin
Author by

Admin

Updated on July 30, 2020

Comments

  • Admin
    Admin over 3 years

    When I'm using textmate, I simply hit "apple+r" and the program gets interpreted. How can I run a program from within notepad++? I see that F5 is for "Run", but pointing that to Python.exe simply opens up a terminal with python running. It does not run my script.

  • Martin Sherburn
    Martin Sherburn about 13 years
    ABSFILE didn't work for me, I had to use this: ****File "%FILE%", line %LINE%, in****
  • yoyo
    yoyo about 12 years
    Works for me (php in my case), and is (double-)clickable, BUT double-clicking only navigates the specified line number in the active file, it doesn't open the file indicated by %ABSFILE%. This makes clickability almost useless when working on library scripts.
  • Eric
    Eric almost 12 years
    To make this work for syntax errors (as well as runtime errors) use *File "%ABSFILE%", line %LINE%. The , in* part won't match on syntax errors as they don't mention the module where the error occurs.
  • Assad Ebrahim
    Assad Ebrahim over 11 years
    If you want to make this super convenient, you can also set up a console shortcut like so: npe_cmdalias p = python "$(FULL_CURRENT_PATH)". This means you can simply popup the console view, type p and your script will run.
  • Jan M.
    Jan M. over 8 years
    The execution window keeps popping up though. Is there a way to suppress this? I want to be able to push F6 and immediately see console output without having to manually close the window each time.
  • Alexander Van Atta
    Alexander Van Atta about 8 years
    ctr+f6 executes the last NppExec
  • Hamman Samuel
    Hamman Samuel almost 8 years
    How do I create a shortcut to terminate a running script?
  • CryptoPiggy
    CryptoPiggy almost 8 years
    @PatronBernard, you can just CTRL+F6.
  • Excellll
    Excellll about 7 years
    FYI link is dead
  • ands
    ands over 5 years
    New link: notepad++ wiki