Share my method of "how to run python script in Notepad++"

  • 1. Why use Python?
    I was writed some small tools with VB6 to improve the job efficency. But VB6 is old, is not supported. Python is so popular. So… After try Pyton, I found that Python is more efficent than VB6, and easier.
    So I finished one python script, named and its copy Mytool.pyw.

    2.Python Script in Notepad++
    Objective: click menu “Run” --> “Mytool”, then the (or Mytool.pyw) runs.
    Procedure(assume Mytool.pyw is in $(NPP_DIRECTORY)\myplugins\Mytool):
    (1) Is it ok that double-click on
    if OK? then go to (2)
    if NOt? add environment variable (depend on your Python install location)
    “PYTHONPATH” = “C:\Users\myPC\AppData\Local\Programs\Python\Python36-32”
    add more “path” = “C:\Users\myPC\AppData\Local\Programs\Python\Python36-32” (Import dont delete your old path, just add more Python location!!!)
    after add the two variable, try double-click on, it should be ok.

    (2) Close Notepad++, open “\Program Files (x86)\Notepad++\shortcuts.xml” by notepad:

    • find <UserDefinedCommands>
    • add one line: <Command name=“Mytool” Ctrl=“no” Alt=“yes” Shift=“no” Key=“119”>$(NPP_DIRECTORY)\myplugins\Mytool\Mytool.pyw</Command>
    • save and exit.

    (3) Run Notepad++
    if OK, then Done!!
    if Not, maybe the Mytool just flash and then disappear. The reason is bad “python current working dir, CWD”.
    To correct the CWD, need modify the (and pyw), add the belowe lines into (after import os,…)
    if os.getcwd() != sys.path[0]:

    then re-run NP++, click “run”–> “Mytool”, try again. It should be ok! For me , It is OK. ^_^.

  • @hycmos

    I’ve read this a few times and have no idea what it is saying??

  • Sorry,This is my first post in this forum.
    It seems a topic can not be modified after 180s. >_<.
    I did not know this before. I sent out a rough draft.

    The topic is about how to run Python script in NP++.
    Before this, I try to find solution in this forum to run Python script by menu “Tools”.
    I didnot find it. Some solution are not for me.

  • @hycmos ,@Alan-Kilborn

    There is a pretty good (disclaimer: I wrote it ! ) step-by-step explanation of some methods of running Pythonscripts in this thread:

  • @Scott-Sumner said:

    @hycmos ,@Alan-Kilborn

    There is a pretty good (disclaimer: I wrote it ! ) step-by-step explanation of some methods of running Pythonscripts in this thread:

    By this method in this 14703 thread, a plugin must be installed. That is why I try new method.
    My method in the topic do not need any NP++ plugin, just only Python is installed in PC.

  • @hycmos

    Ah, thought you were talking about “Pythonscript” (the scripting plugin) when in reality you were talking about “Python scripts”.

    For your usage I prefer “Python programs” as when you talk about Python “scripts” people that don’t know get the impression that Python programming is not real programming. I guess they equate it to batch file writing, or shell “scripts”, or something very trivial…who knows, can’t read minds… [Certainly not trying to trivialize batch or shell scripting with that comment!]

  • @Scott-Sumner
    Actually, I am not good at programming. I used VB6 to write code to implent some small tools before.
    But Billgates dont update VB6. So I must sellect another language. I decide to use Python just because many peple talk it on web. I have no idea about other languages.

Log in to reply