Community
    • Login

    No module named Npp

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    pythonscript
    32 Posts 4 Posters 7.0k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • dailD
      dail @Alina Gubanova
      last edited by

      @Alina-Gubanova How are you launching the script? Inside of Notepad++?

      Alina GubanovaA 1 Reply Last reply Reply Quote 1
      • Alina GubanovaA
        Alina Gubanova @dail
        last edited by

        @dail yes.
        So these are my steps:
        Run -> Python (where I saved C:…\Python2.7\Lib\idlelib\idle.py “$(FULL_CURRENT_PATH)”) -> IDLE opens up in a new window -> press F5 -> Traceback (most recent call last): File "C:\Users\agubanova\Notepad++\plugins\PythonScript\scripts\new script.py", line 3, in <module> import Npp; ImportError: No module named Npp

        Alan KilbornA 1 Reply Last reply Reply Quote 1
        • Alina GubanovaA
          Alina Gubanova @guy038
          last edited by

          @guy038 thank you so much for putting your time in such a detailed explanation. I should definitely update my N++ version :)
          I followed every step of your explanation, and I still get an error. When you Run the script what is the directory that you use?

          I suspect mine could be wrong. Is it C:…\Python2.7\Lib\idlelib\idle.py “$(FULL_CURRENT_PATH)” ?

          1 Reply Last reply Reply Quote 2
          • Alan KilbornA
            Alan Kilborn @Alina Gubanova
            last edited by Alan Kilborn

            @Alina-Gubanova said:

            So these are my steps

            You could have said that in the beginning and saved some time. You can’t run a Pythonscript that way. It isn’t going to know about the special “notepad” objects. You have to run it from the Pythonscript menu, as I said earlier.

            Alina GubanovaA dailD 2 Replies Last reply Reply Quote 4
            • guy038G
              guy038
              last edited by

              Hi, @alina-gubanova,

              Before, describing the tree structure of my D:\@à\763 folder, note two points :

              • The install folder of a portable N++ version must be different from, either, C\Program files and C\Program files (x86)

              • Any local installation of Notepad++ needs the zero-length file, doLocalConf.xml, along with the executable notepad++.exe

              This file, installed by default, assures you that any file created and/or handled by Notepad++, will be located inside the installation folder ;-))


              Depending of your system, follow one of these links, below, to download the last portable N++ v7.7.1

              https://notepad-plus-plus.org/repository/7.x/7.7.1/npp.7.7.1.bin.zip

              https://notepad-plus-plus.org/repository/7.x/7.7.1/npp.7.7.1.bin.x64.zip

              Just create any folder in your system and extract the contents of the archive in this folder !

              On the other hand, I’m using the PythonScript v1.3.0.0 ( PythonScript_Full_1.3.0.0.zip ) but you’ll find the latest release v1.4.0.0 , below :

              https://github.com/bruderstein/PythonScript/releases

              Note that, from N++ version v7.6 and above, there’s a new organization of plugins, in the Plugins folder. From now on, any plugin, let’s say myFirstPlugin.dll, must be moved inside a folder named the same way, so myFirstPlugin !


              OK, as promised, here is the tree structure of my D:\@@\763 folder :

              D:\@@\763
              	\
              	|
              	|-- autoCompletion (folder)
              	|                \
              	|                |-- ".xml" files
              	|
              	|
              	|-- localization (folder)
              	|              \
              	|              |-- ".xml" files
              	|
              	|
              	|-- plugins (folder)
              	|         \
              	|         |
              	|         |-- Config (folder)
              	|         |        \
              	|         |        |
              	|         |        |-- Hunspell (folder)
              	|         |        |          \
              	|         |        |          |-- en_US.aff
              	|         |        |          |
              	|         |        |          |-- en_US.dic
              	|         |        |
              	|         |        |
              	|         |        |-- PythonScript (folder)
              	|         |        |              \
              	|         |        |              |-- scripts (folder)
              	|         |        |                        \
              	|         |        |                         |-- Alina.py ( YOUR script )
              	|         |        |
              	|         |        |
              	|         |        |-- ".ini" files
              	|         |        |
              	|         |        |
              	|         |        |-- nppPluginList.dll
              	|         |
              	|         |
              	|         |-- doc (folder)
              	|         |     \
              	|         |      |-- PythonScript(folder)
              	|         |                     \
              	|         |                     |-- _sources (folder)
              	|         |                     |
              	|         |                     |-- _static  (folder)
              	|         |                     |
              	|         |                     |-- ".html" files and Miscellaneous files
              	|         |
              	|         |
              	|         |-- DSpellCheck (folder)
              	|         |             \
              	|         |             |-- DSpellCheck.dll
              	|         |
              	|         |
              	|         |-- mineTools (folder)
              	|         |           \
              	|         |           |-- mineTools.dll
              	|         |
              	|         |
              	|         |-- NppConverter (folder)
              	|         |              \
              	|         |              |-- NppConverter.dll
              	|         |
              	|         |
              	|         |-- NppExport (folder)
              	|         |           \
              	|         |           |-- NppExport.dll
              	|         |
              	|         |
              	|         |-- PythonScript (folder)
              	|                        \
              	|                        |-- lib (folder)
              	|                        |     \
              	|                        |      |-- Sub-folders
              	|                        |      |
              	|                        |      |-- ".py" files
              	|                        |
              	|                        |
              	|                        |-- scripts (folder)
              	|                        |         \
              	|                        |         |-- Samples (folder)
              	|                        |         |         \
              	|                        |         |         |-- ".py" scripts
              	|                        |         |
              	|                        |         |-- startup.py
              	|                        |
              	|                        |
              	|                        |-- PythonScript.dll  ( Version 1.3.0.0 )
              	|
              	|
              	|-- Test
              	|      \
              	|      |-- File_1.txt
              	|      |
              	|      |-- File_2.txt
              	|
              	|
              	|
              	|-- themes (folder)
              	|        \
              	|        |-- ".xml" files
              	|
              	|
              	|-- updater (folder)
              	|         \
              	|         |-- GUP.exe
              	|         |
              	|         |-- gup.xml
              	|         |
              	|         |-- libcurl.dll
              	|
              	|
              	|-- doLocalConf.xml
              	|
              	|
              	|-- Notepad++.exe  ( Version 7.6.3 )
              	|
              	|
              	|-- python27.dll
              	|
              	|
              	|-- SciLexer.dll
              	|
              	|
              	|-- Some ".txt" files
              	|
              	|
              	|-- Some ".xml" CONFIGURATION files
              

              I Just hope that you’ll get some part useful !

              Cheers,

              guy038

              Alina GubanovaA 1 Reply Last reply Reply Quote 3
              • Alina GubanovaA
                Alina Gubanova @Alan Kilborn
                last edited by

                @Alan-Kilborn I apologize for the confusion. Followed the steps that were suggested by a coworker, so wasn’t aware of the issue. I’ll try running it that way. Thank you for your time

                Alan KilbornA 1 Reply Last reply Reply Quote 0
                • Alina GubanovaA
                  Alina Gubanova @guy038
                  last edited by

                  @guy038 thank you so much for putting time into this and offering some useful advice! I’ll make sure to follow the steps and let you know!

                  1 Reply Last reply Reply Quote 1
                  • dailD
                    dail @Alan Kilborn
                    last edited by

                    @Alan-Kilborn said:

                    @Alina-Gubanova said:

                    So these are my steps

                    You could have said that in the beginning and saved some time. You can’t run a Pythonscript that way. It isn’t going to know about the special “notepad” objects. You have to run it from the Pythonscript menu, as I said earlier.

                    My suspicion was correct :)

                    Alan KilbornA 1 Reply Last reply Reply Quote 2
                    • Alan KilbornA
                      Alan Kilborn @dail
                      last edited by

                      @dail said:

                      My suspicion was correct

                      Yes, except technically the OP was launching it from within Notepad++. But…there are degrees of within, and when you are wanting to do operations with Python tight to the Scintilla and Notepad++ cores (the original script used the notepad object), you have to be REALLY within. :)

                      • Run menu : sorta within, but mostly not because it is just telling Notepad++ to launch an external process

                      • Pythonscript menu : really within, because it is using the Python interpreter part of the plugin (and can access the editor (Scintilla) and notepad (N++) objects.

                      And @dail, I know you know all this … I write it for the edification of other readers. :)

                      1 Reply Last reply Reply Quote 6
                      • Alan KilbornA
                        Alan Kilborn @Alina Gubanova
                        last edited by

                        @Alina-Gubanova said:

                        I apologize for the confusion. Followed the steps that were suggested by a coworker…

                        No apology needed – it slowed you down in getting a solution you needed, is all. Didn’t hurt me/us a bit. :)

                        Never trust those shifty coworkers!! ;)

                        Write back if you need more help. If you don’t need more help, just upvote the postings here that helped you most.

                        Alina GubanovaA 1 Reply Last reply Reply Quote 2
                        • Alina GubanovaA
                          Alina Gubanova @Alan Kilborn
                          last edited by

                          @Alan-Kilborn Just to be very clear: I save the script that I need and then run it directly from the Pythonscript menu:
                          Plugins -> Python Scropt -> Scripts -> nameofmyscript.
                          Tried it just now, it seems like nothing is happening. It just opens a new window new1. Console is empty as well.
                          What step am I missing?

                          Alan KilbornA 1 Reply Last reply Reply Quote 0
                          • Alan KilbornA
                            Alan Kilborn @Alina Gubanova
                            last edited by

                            @Alina-Gubanova

                            I think you are on the right track for running your script now.

                            I presume you are trying to run the original script you posted? If that’s the case, I don’t see any reason why a new1 window would be opened. Perhaps you should add some more console.write() statements to the script to attempt to track control flow?

                            Alina GubanovaA 1 Reply Last reply Reply Quote 0
                            • Alina GubanovaA
                              Alina Gubanova @Alan Kilborn
                              last edited by

                              @Alan-Kilborn Now I just get Traceback (most recent call last): File "C:\...\Notepad++\plugins\PythonScript\scripts\convertutf8.py", line 14, in <module> console.write() Boost.Python.ArgumentError: Python argument types in Console.write(Console) did not match C++ signature: write(class NppPythonScript::PythonConsole {lvalue}, class boost::python::api::object) when I added some console.write()

                              Alan KilbornA 1 Reply Last reply Reply Quote 0
                              • Alan KilbornA
                                Alan Kilborn @Alina Gubanova
                                last edited by

                                Well, from the error message I’d assume that you put console.write() directly in your code. What I mean was to put something like console.write('got here!') at a strategic place or putting a variable name inside the parens, or…just in general some debugging techniques that one might do when programming Python without an IDE.

                                Like @guy038, when I run your original script on some test files, it seems to do what you intend.

                                I’m assuming you got this working script from a coworker as you hinted before. Perhaps asking him/her for help getting it going is a better path than us trying to help you from afar.

                                Alina GubanovaA 1 Reply Last reply Reply Quote 2
                                • Alina GubanovaA
                                  Alina Gubanova @Alan Kilborn
                                  last edited by

                                  @Alan-Kilborn Okay, will do! Thank you again!

                                  1 Reply Last reply Reply Quote 1
                                  • guy038G
                                    guy038
                                    last edited by guy038

                                    Hello, @alina-gubanova,

                                    I don’t really understand why you cannot get it straight. It should be practically obvious !

                                    • Create a folder, outside C\Program files..., on your configuration

                                    • Install a recent portable N++ version by extracting the archive’s contents inside this folder

                                    • Install a recent PythonScript release, by extracting the archive’s contents inside this folder

                                    • Verify that the tree structure, of this new installation folder of N++, is like in my previous post

                                    • Open Notepad++

                                    • Select the option Plugins > PythonScript > New Script

                                    • Enter a name for your script, let’s say Alina and click on the Save button

                                    => A new tab, Alina.py is, then, displayed

                                    • Paste the contents of your script, below, changing, of course, the value of the filePathSrc variable
                                    import os;
                                    import sys;
                                    import Npp;
                                    from Npp import notepad
                                    
                                    filePathSrc="X:\\xxxxxxxxxxxxt" # Path to the folder with files to convert
                                    
                                    for root, dirs, files in os.walk(filePathSrc):
                                        for fn in files:
                                            if fn[-4:] == '.txt':
                                                 notepad.open(root + "\\" + fn)
                                                 console.write(root + "\\" + fn + "\r\n")
                                                 notepad.runMenuCommand("Encoding", "Convert to UTF-8")
                                                 notepad.save()
                                    notepad.close()
                                    
                                    • Save the Alina.py Python file

                                    • Close and restart Notepad++ ( IMPORTANT as your script will be found, inside the Python files list)

                                    • Choose the option Plugins > PythonScript > Show Console, just to visualize possible errors

                                    • Then, run your script, by selecting the option Plugins > PythonScript > Scripts > Alina

                                    => The absolute paths of all the files of your folder should be displayed on the Python console

                                    Done ! Here we are ;-))

                                    Best Regards,

                                    guy038

                                    Alina GubanovaA Alan KilbornA 2 Replies Last reply Reply Quote 1
                                    • Alina GubanovaA
                                      Alina Gubanova @guy038
                                      last edited by

                                      @guy038 Once again, I appreciate your time commitment and input into this issue. I too find it frustrating that I cannot get such an easy thing to work, and as you can see I obviously do not have much experience working with N++. I assure you, from what I am looking at, I have performed all of the steps that you have described correctly, but I will make sure to reinstall the newer version of n++ in case something went wrong during installation.

                                      1 Reply Last reply Reply Quote 2
                                      • Alan KilbornA
                                        Alan Kilborn @guy038
                                        last edited by Alan Kilborn

                                        @guy038 said:

                                        I don’t really understand while you cannot get it straight. It should be practically obvious !

                                        Maybe a tad harsh. A reinstall of things is definitely not easy given the current state of things with the Pythonscript plugin. But…to me it sounded like the OP had PS installed correctly from the beginning, just the approach to running a script was wrong. That all being said, it is tough to determine currently what is going wrong.

                                        1 Reply Last reply Reply Quote 2
                                        • Alina GubanovaA
                                          Alina Gubanova
                                          last edited by Alina Gubanova

                                          @Alan-Kilborn @guy038 Issue fixed. Changed filePathSrc= "some directory" to filePathSrc= r"somedirectory"
                                          and everything worked fine.

                                          Alan KilbornA 1 Reply Last reply Reply Quote 4
                                          • Alan KilbornA
                                            Alan Kilborn @Alina Gubanova
                                            last edited by

                                            @Alina-Gubanova

                                            Of course, we could have never debugged THAT from here. :)

                                            Alina GubanovaA 1 Reply Last reply Reply Quote 3
                                            • First post
                                              Last post
                                            The Community of users of the Notepad++ text editor.
                                            Powered by NodeBB | Contributors