Menu

Notepad++ as a Python IDE

Peter
2008-08-25
2012-11-13
  • Peter

    Peter - 2008-08-25

    Is it possible to use Notepad++ as an "IDE" for Python?  I would like to be able to use the "Run" command to execute Python code that I am currently editing.

    I tried to search this forum but with little luck.

    Any help is most appreciated.

    Regards,
    Peter

     
    • Sam

      Sam - 2008-10-03

      I agree with Airdrik here.

      An integrated python debugger would do wonders for NPP. Especially when there are not too many clean debuggers freely available for Python. Probably, when my work reduces, I'll try my hand at it ;-)

      Re,
      Sam

       
    • M. B. Huffman

      M. B. Huffman - 2008-08-25

      Here is what works for me:

      1. Create a batch file in the Notepad++ directory:
          @echo off
          rem runpy.bat

          set /P ARGV="Arguments: "
          echo.
          if "%ARGV%"=="" cls

          rem %1 is quoted in shortcuts.xml; do not add quotes to %1 here
          D:\Python25\python %1 %ARGV%
          echo.
          pause

      2. Create a shortcut in shortcuts.xml with this command:
          $(NPP_DIRECTORY)\runpy.bat "$(FULL_CURRENT_PATH)"

      The line
          set /P ARGV="Arguments: "
      is so I can send command line arguments to the Python program.

      Another possibility is to run Python with the -i switch so that you remain in the interactive shell, which is handy for examining the values of the program's variables.

      I have it set up in the Run menu with a Ctrl+Alt+Shift+Y short cut ('P' was already used by a similar shortcut for Perl).

      Hope this at least gives you some ideas so you can develop something that works for you.

      Mike

       
      • Creative

        Creative - 2008-09-02

        Sorry I can't understand your instructions. Here is what I did:
        made a file runpy.bat in the notepad++ folder containing:

        @echo off
        rem runpy.bat

        set /P ARGV="Arguments: "
        echo.
        if "%ARGV%"=="" cls

        rem %1 is quoted in shortcuts.xml; do not add quotes to %1 here
        D:\Python25\python %1 %ARGV%
        echo.
        pause

        then i edited the xml file and saved it:
        <NotepadPlus>
            <InternalCommands />
            <Macros>
                <Macro name="Trim Trailing and save" Ctrl="no" Alt="yes" Shift="yes" Key="83">
                    <Action type="1" message="2170" wParam="0" lParam="0" sParam=" " />
                    <Action type="1" message="2170" wParam="0" lParam="0" sParam=" " />
                    <Action type="1" message="2170" wParam="0" lParam="0" sParam=" " />
                    <Action type="0" message="2327" wParam="0" lParam="0" sParam="" />
                    <Action type="0" message="2327" wParam="0" lParam="0" sParam="" />
                    <Action type="2" message="0" wParam="42024" lParam="0" sParam="" />
                    <Action type="2" message="0" wParam="41006" lParam="0" sParam="" />
                </Macro>
            </Macros>
            <UserDefinedCommands>
                <Command name="launch in Firefox" Ctrl="yes" Alt="yes" Shift="yes" Key="88">firefox &quot;$(FULL_CURRENT_PATH)&quot;</Command>
                <Command name="launch in IE" Ctrl="yes" Alt="yes" Shift="yes" Key="73">iexplore &quot;$(FULL_CURRENT_PATH)&quot;</Command>
                <Command name="Get php help" Ctrl="no" Alt="yes" Shift="no" Key="112">http://www.php.net/%20$(CURRENT_WORD)</Command>
                <Command name="Google Search" Ctrl="no" Alt="yes" Shift="no" Key="113">http://www.google.com/search?q=$(CURRENT_WORD)</Command>
                <Command name="Wikipedia Search" Ctrl="no" Alt="yes" Shift="no" Key="114">http://en.wikipedia.org/wiki/Special:Search?search=$(CURRENT_WORD)</Command>
                <Command name="open file" Ctrl="no" Alt="yes" Shift="no" Key="116">$(NPP_DIRECTORY)\notepad++.exe $(CURRENT_WORD)</Command>
                <Command name="open file" Ctrl="no" Alt="yes" Shift="no" Key="79">$(NPP_DIRECTORY)\runpy.bat "$(FULL_CURRENT_PATH)"</Command>
                <Command name="open in another instance" Ctrl="no" Alt="yes" Shift="no" Key="117">$(NPP_DIRECTORY)\notepad++.exe $(CURRENT_WORD) -nosession -multiInst</Command>
            </UserDefinedCommands>
            <PluginCommands />
            <ScintillaKeys />
        </NotepadPlus>

        im assuming the alt=yes and key = 79 would mean alt+o would do something? when i do this nothing happens.

         
        • Creative

          Creative - 2008-09-04

          i noticed its not refreshing.

          say i edit
          <Command name="Google Search" Ctrl="no" Alt="yes" Shift="no" Key="113">http://www.google.com/search?q=$(CURRENT_WORD)</Command>

          to

          <Command name="TESTING IF THIS CHANGES ANYTHING" Ctrl="no" Alt="yes" Shift="no" Key="113">http://www.SOMETHING.com/search?q=$(CURRENT_WORD)</Command>

          then i save the file in the notepad++ folder,
          then when i open notepad it will still say Google Search, and the shortcut will still take me to google.com

           
      • Creative

        Creative - 2008-09-03

        I must be close to having this working...
        here is my updated xml file:
        http://www.nomorepasting.com/getpaste.php?pasteid=19837
        i changed it to alt + 106 which is alt j right?

        a added more & q u o t e s ; because notepad is in C:/programfiles/notepad++

        also i edited the .bat file so it is C:/python25 rather than D:/python25 because i python is in C:/

         
    • M. B. Huffman

      M. B. Huffman - 2008-09-03

      My first guess is that you have Alt+O assigned to something else; look at your key assignments in Shortcut mapper.

      My next guess is that your NPP_DIRECTORY has a space somewhere in the path; if so quote that Notepad++ environment variable the same as your did FULL_CURRENT_PATH (be sure to use the XML character entity, NOT the literal double-quote character.

      I see in my post that the forum displayed it as the quote character (I did not notice that before). In the xml file you need to use the character entity ampersand+q+u+o+t+semicolon: & q u o t ; (without the spaces).

      Mike

       
      • Creative

        Creative - 2008-09-03

        here is my edited xml file, did i follow your instructions corretly with the quote thing?
        http://www.nomorepasting.com/getpaste.php?pasteid=19827

        please not that im very new to programming and dont know any xml. what exactly did you mean by:
        NPP_DIRECTORY
        and
        quote that Notepad++ environment variable

        sorry im such a noob :X
        also i made te command name="runpyth"

         
    • M. B. Huffman

      M. B. Huffman - 2008-09-03

      Yes, the quoting looks correct.
      If there is a space in the path where Notepad++ in installed (such as Program Files) then you need to surround $(NPP_DIRECTORY)\runpy.bat in quotes as well (using the character entity as described previously)

      Also, I note in your latest version you have duplicated the Alt+F2 key; be sure to use a key combination that is not already in use.

      Mike

       
    • Creative

      Creative - 2008-09-03

      http://www.asciitable.com/ is what i used for the letters, i tried both 106 and 74 for j

       
    • M. B. Huffman

      M. B. Huffman - 2008-09-03

      If you want the key to be Alt+J then use the upper-case ASCII code: 74.

      You should be able to look at the Run menu and see your command listed with the short-cut key. Also in Shortcut Mapper.

      The easiest way to create a macro is to use the Run command (F-5): get the command to work, then use the Save dialog to select a key; that way you don't have to worry about ASCII codes. However, be sure to use a key that is not already in use (scroll through Shortcut Mapper to see what keys are in use).

      C:/programfiles/notepad++ does not have spaces, so you should not need quotes.

       
      • Creative

        Creative - 2008-09-04

        i think my xml file and bat file are correct.

        http://img87.imageshack.us/img87/6769/aoeuaz6.jpg

        as you  can see my program isnt listed in the run menu. it wasnt listed in the shortcut mapper either. why is this? does this mean my xml file is wrong? or do i need to save a "macro" or something using notepad?

        i have no idea what to type in the green oval shown in my pic. is that supposed to link to my bat file? the python.exe or IDLE python GUI or python shell? I'm not really sure what im looking for or where it is. none of this makes any sense to me :(

         
        • M. B. Huffman

          M. B. Huffman - 2008-09-04

          >> as you can see my program isnt listed in the run menu.
          >> it wasnt listed in the shortcut mapper either.

          Are you editing shortcuts.xml with Notepad++? Recent versions of Notepad++ seem to lock the configuration files; any changes you make are not saved (and you don't get a warning). Make your edits to shortcuts.xml with a different editor (or a different copy/version of Notepad++).

          Better yet, don't try to edit shortcuts.xml at all; get your command working in the Run menu and save it. Then, if you want, go back and look at shortcuts.xml to see how it was saved and use that as a basis if you want to tinker with the xml file directly.

           
        • M. B. Huffman

          M. B. Huffman - 2008-09-04

          >> it should say Hello World

          No, it shouldn't. The command C:\Python25\python.exe in the Notepad++ Run menu should do exactly what the same command would do in the Windows->Start->Run menu, and exactly what it would do if entered in a Windows Console (command prompt): It should start the Python interactive shell because you did not provide the name of a Python source file.

          From the screen shot it looks like hello.py is in the Python installation directory, so your Run command should be:
          C:\Python25\python C:\Python25\hello.py

           
    • Creative

      Creative - 2008-09-04

      http://bytes.com/forum/thread698915.html

      i tried following that guide also.

       
    • Sam

      Sam - 2008-10-02

      Around the same time this thread was started here, I had started one in "Help" section. After a bit of fiddling around, I did manage to even get NPP to debug Python scripts for me.

      Take a look at http://sourceforge.net/forum/forum.php?thread_id=2163921&forum_id=331754

      Now I'm using NPP full time for Python scripting, running and debugging.

      Cheers!
      Sam

      P.S. Thanks mhuffman, it was your post which lead me to this.

       
    • Airdrik

      Airdrik - 2008-10-02

      The simplest way would be to use the line:

      <Command name="Run Current Document" Ctrl="yes" Alt="no" Shift="no" Key="116">&quot ;$(FULL_CURRENT_PATH)&quot ;</Command>

      This utilizes Windows file associations to pick the correct program for executing the current file.  Assuming that python is associated with .py files, running this when the current file is a python file will execute it with python.  This has the added bonus (for those working in mixed language environments) that you can run any file types that windows recognizes.  (Or the drawback that it doesn't work if you've associated NotePad++ with your .py files, which will result in merely reopening the current file in NP++)

      Alternatively, a new feature (plugin) suggestion would be to make an integrated python debugger similar to the php debugger plugin: DBGP. 

       
MongoDB Logo MongoDB