Community
    • Login

    Adding Libraries to PythonScript Plugin

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    40 Posts 5 Posters 8.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.
    • John Doe 1J
      John Doe 1
      last edited by

      Hello everyone! I am new to developing Notepad++ plugins and have been using PythonScript so far to make some scripts for my specific needs. The issue I’ve run into is adding plugins for me to use with my PythonScript scripts. I tried adding “Pandas” to aid in my development but if I add the import statement to a simple Hello World script it breaks. So my question is how do I add that library (or any other for that matter) to my PythonScript environment? If I want to use Pandas in PyCharm it’s as easy as going to the Python Packages tab and installing it, but how can I make it available to my PythonScript environment? Any help would be greatly appreciated, I’ve been searching far and wide with no luck so far.

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @John Doe 1
        last edited by

        @john-doe-1

        Sounds like you want to tick this box in the PythonScript Configuration window:

        13e35c6f-1932-4ea4-88a6-6524a6c1d6e2-image.png

        Side note: Pandas is awesome, but not always easy. :-)

        John Doe 1J 2 Replies Last reply Reply Quote 2
        • John Doe 1J
          John Doe 1 @Alan Kilborn
          last edited by

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • John Doe 1J
            John Doe 1 @Alan Kilborn
            last edited by

            @alan-kilborn I just checked the box but a simple Hello World script still fails with this import statement above it “import pandas as pandasForSortingCSV”.

            I’ve read on some forums that the “lib” or “site-packages” are where you drop you’re packages so that PythonScript can access them, I have tried both of these locations to no avail.

            By the way these are the files I placed in those folders, is there some different kind of file for packages that I am unaware of? I keep seeing the .tar extension.

            notepad.png

            Alan KilbornA Michael VincentM 2 Replies Last reply Reply Quote 0
            • Alan KilbornA
              Alan Kilborn @John Doe 1
              last edited by

              @john-doe-1

              I don’t know that this forum is the place for obtaining help on installing non-Notepad++ related Python components.

              John Doe 1J 1 Reply Last reply Reply Quote 2
              • Michael VincentM
                Michael Vincent @John Doe 1
                last edited by

                @john-doe-1 said in Adding Libraries to PythonScript Plugin:

                I’ve read on some forums that the “lib” or “site-packages” are where you drop you’re packages

                You definitely don’t “drop packages” - especially as .tar archives for Python. Use pip (Python package management) to install them properly for your distribution.

                Cheers.

                John Doe 1J 2 Replies Last reply Reply Quote 3
                • John Doe 1J
                  John Doe 1 @Michael Vincent
                  last edited by

                  @michael-vincent I followed these instructions exactly (from the creator of PythonScript) and dropped in the packages that Pandas is dependent on, still no luck.

                  notepad.png

                  1 Reply Last reply Reply Quote 0
                  • John Doe 1J
                    John Doe 1 @Alan Kilborn
                    last edited by

                    @alan-kilborn I can install components on PyCharm, the issue is getting them to work with the PythonScript environment within Notepad++.

                    1 Reply Last reply Reply Quote 0
                    • John Doe 1J
                      John Doe 1 @Michael Vincent
                      last edited by

                      @michael-vincent By the way this is the Pandas folder I dropped into lib,

                      pandas1.png
                      pandas2.png

                      Michael VincentM PeterJonesP 2 Replies Last reply Reply Quote 0
                      • Michael VincentM
                        Michael Vincent @John Doe 1
                        last edited by

                        @john-doe-1 said in Adding Libraries to PythonScript Plugin:

                        By the way this is the Pandas folder I dropped into lib,

                        I have no idea what you’re doing dropping folders in random locations. Python will not just work - you need to install things properly.

                        First off, you should match your PythonScript Python version with your system Python. I am running PythonScript 3.0.7-alpha since it is compiled against Python 3.8 and my system Python is 3.8:

                        PS VinsWorldcom ~ > python3 -V
                        Python 3.8.10
                        

                        Next, I install all my Python modules properly:

                        python3 -mpip install MODULE_NAME
                        

                        Finally, they are all just seen by PythonScript with no additional copying folders anywhere:

                          File "C:\usr\bin\npp64\plugins\Config\PythonScript\scripts\startup.py", line 1 : PythonScript initialized
                        Python 3.8.9 (tags/v3.8.9:a743f81, Apr  2 2021, 11:10:41) [MSC v.1928 64 bit (AMD64)]
                        Initialisation took 1047ms
                        Ready.
                        >>> print(sys.path)
                        ['C:\\usr\\bin\\npp64\\plugins\\PythonScript\\lib'
                         'C:\\usr\\bin\\npp64\\plugins\\Config\\PythonScript\\lib'
                         'C:\\usr\\bin\\npp64\\plugins\\PythonScript\\scripts'
                         'C:\\usr\\bin\\npp64\\plugins\\Config\\PythonScript\\scripts'
                         'C:\\usr\\bin\\npp64\\plugins\\PythonScript\\lib\\lib-tk'
                         'C:\\usr\\bin\\npp64\\plugins\\PythonScript\\python38.zip'
                         'C:\\Python3\\Lib'
                         'C:\\Python3\\DLLs'
                         'C:\\usr\\bin\\npp64'
                         'C:\\Users\\VinsWorldcom\\AppData\\Roaming\\Python\\Python38\\site-packages'
                         'C:\\Users\\VinsWorldcom\\AppData\\Roaming\\Python\\Python38\\site-packages\\win32'
                         'C:\\Users\\VinsWorldcom\\AppData\\Roaming\\Python\\Python38\\site-packages\\win32\\lib'
                         'C:\\Users\\VinsWorldcom\\AppData\\Roaming\\Python\\Python38\\site-packages\\Pythonwin'
                         'C:\\Python3'
                         'C:\\Python3\\lib\\site-packages']
                        

                        Cheers.

                        1 Reply Last reply Reply Quote 2
                        • PeterJonesP
                          PeterJones @John Doe 1
                          last edited by PeterJones

                          @john-doe-1 ,

                          You have some fundamental misunderstandings:

                          A .tar file does not meet the definition of terms used in the conversation between Robert and Dave that you imaged. A .tar file, like a .zip or .7z, is an archive containing multiple files. You have to extract the contents of that archive to be able to install it per those instructions. Please note, as Alan said, this paragraph has nothing to do with Notepad++, and such fundamental computing queries should happen in forums dedicated to basic computer questions, not in a forum dedicated to the Notepad++ application.

                          If you followed Dave’s actual instructions (putting the directory and files, not a raw .tar file) in the PythonScript\lib directory, then all the setup that you did earlier, where you changed to “prefer installed python libraries” to use your own Python installation instead of the python27.dll bundled with PythonScript, will just get in the way – because you are no longer defaulting to the bundled libraries, you are defaulting to use the libraries of the separately-installed python. If you already followed the steps from earlier in the discussion here, where you checked that checkbox, then to install a new module, you would use the normal techniques and instructions to install any python module in that installation – you could use pip as was already recommended to you by Michael, or (I think) you could do a manual installation (for pure-python modules, dropping the directory into the appropriate lib location for your python installation – but I’m not a python expert, so don’t quote me on python module installation instructions, and don’t use the raw-drop unless you know what you’re doing; pip is the right way). But again, for installing with pip or a manual install, into a normally-installed python instance, you would follow generic python advice on the internet (like a python help site), and not come to a Notepad++ specific forum.

                          If you really wanted to install in the PythonScript\lib hierarchy that Dave mentioned in the image, then turn off that checkbox that Alan mentioned, and make sure you have the original python27.dll, not the one that you overwrote if you followed the checkbox instructions correctly. Then you would follow Dave’s instructions and place the extracted directory (not the .tar file) in the PythonScript\lib folder. But that, as Dave said, would only work if the module you are installing is a pure-python file. I know nothing about Pandas, and whether it is pure python or not. Again, any python questions that aren’t specific to Notepad++, like whether Pandas is pure python or not, belong in a Python or Pandas forum, not in a Notepad++ forum.

                          At this point, you might want to take a step back, and give more details

                          1. Do you already have a Python2.7 executable with DLL installed elsewhere on your machine? If so, what is the path for that installation – paths for both the executable and its libraries would be helpful; also, check if the python27.dll is in the c:\Windows\ directory (or equivalent location on your configuration).
                            • or if you have some other version, let us know.
                          2. Which version of PythonScript plugin do you have installed? Where is it installed? What is the date and exact size on the python27.dll in the Notepad++\plugins\PythonScript folder
                          3. Have you researched Pandas enough to know if it is pure python or not? (That research has to happen elsewhere; you can just report the results here in your reply)
                          4. Where exactly did you put Pandas – and did you do it as a .tar as you originally said, or as a directory as your screenshot implies. Full path again, please.
                          5. Is your intention to want to use the exact same Python for both normal command-line python development and for PythonScript? Or are you willing to or wanting to keep those two separate? Really, I personally think it’s best conceptually to keep the two separate, so that way you’ve got the interpreter DLL and libraries that are used for your Notepad++ automation scripts in the PythonScript hierarchy, and a separate Python instance for normal command-line Python usage. You will find that you really don’t need that many fancy modules installed in the PythonScript instance, because for the scripts that you are running inside Notepad++ using the PythonScript plugin, whose sole purpose for existing is to automate Notepad++, you don’t need a lot of fancy modules.

                          Looking at what “Pandas” module does, it is a data analysis library. I cannot see any reason for embedding a data analysis library in a script that is automating some small text manipulation in Notepad++.

                          I think I may have found another fundamental misunderstanding. If you have a python executable already, and just want to use Notepad++ to type source code to develop your python code, and maybe even run python applications that you are developing, you do not need the PythonScript plugin to accomplish this. (That is, if you are just trying to replace the PyCharm IDE with Notepad++). Just edit the source code in Notepad++, and use the Notepad++ Run menu (or the batch-processing NppExec to do fancier stuff to run your python application while developing it). Once again, if it’s not clear, PythonScript is intended to act as a way to automate text-editing tasks inside notepad++, like doing fancier search-and-replace-with-a-bit-extra-logic. It is not a generic “develop a python program to use for non-Notepad++-related tasks” plugin.

                          John Doe 1J 2 Replies Last reply Reply Quote 4
                          • John Doe 1J
                            John Doe 1 @PeterJones
                            last edited by

                            This post is deleted!
                            1 Reply Last reply Reply Quote 0
                            • John Doe 1J
                              John Doe 1 @PeterJones
                              last edited by

                              @peterjones @Michael-Vincent Thank you for the extensive explanations, they have helped clear up several misunderstandings. I am going to go ahead and try the method @Michael-Vincent recommended since I am unsure if Pandas is pure Python or not. A few weeks ago I had installed the latest version of Python and then today uninstalled it and installed Python 2.7 to match PythonScript. I found the python27.dll in my System32 folder but it is dated to a few weeks ago, is this the correct dll to put into the Notepad++ directory?

                              PeterJonesP Alan KilbornA 2 Replies Last reply Reply Quote 1
                              • PeterJonesP
                                PeterJones @John Doe 1
                                last edited by PeterJones

                                @john-doe-1 said in Adding Libraries to PythonScript Plugin:

                                I found the python27.dll in my System32 folder but it is dated to a few weeks ago, is this the correct dll to put into the Notepad++ directory?

                                Yes, the python27.dll from the system32 folder should be written overtop of the python27.dll that was in c:\program files\notepad++\plugins\pythonscript\ directory (or equivalent for your installation) (in case it wasn’t apparent, after you do that, you need to restart Notepad++ to get PythonScript to see the new DLL and libraries)

                                My guess is that the date on the python27.dll in the system folder was the compile date inside the installer, not the date you installed Python 2.7, but that’s just a guess.

                                John Doe 1J 1 Reply Last reply Reply Quote 1
                                • John Doe 1J
                                  John Doe 1 @PeterJones
                                  last edited by

                                  @peterjones Okay I finally got Windows to recognize my Python version and installed pandas:

                                  pandas3.png

                                  I’ve updated the Python27.dll and checked the box in the configuration box.

                                  My script still will not run nothing happens, this is the script I am using for testing whether or not the import is successful by the way:

                                  from Npp import *
                                  import pandas as pandasForSortingCSV

                                  notepad.messageBox(“Welcome!”, “Welcome!”)
                                  notepad.messageBox(“Hello!”, “Hello!”)

                                  PeterJonesP 1 Reply Last reply Reply Quote 0
                                  • Alan KilbornA
                                    Alan Kilborn @John Doe 1
                                    last edited by Alan Kilborn

                                    @john-doe-1

                                    So I’ll (re)ask something Notepad++ related, that Peter asked already: What are you planning to do, specifically with the text of a Notepad++ window, such that you need Pandas to do it?

                                    EDIT: Ok, maybe this provides a hint: “pandasForSortingCSV” :-)

                                    John Doe 1J 1 Reply Last reply Reply Quote 1
                                    • PeterJonesP
                                      PeterJones @John Doe 1
                                      last edited by

                                      @john-doe-1 said in Adding Libraries to PythonScript Plugin:

                                      My script still will not run nothing happens,

                                      Suggestions for debug:

                                      Restart Notepad++.

                                      Use Plugins > PythonScript > Show Console. Show us the contents of the console with all the startup information.

                                      Then from the >>> input field in the console, write notepad.messageBox("Welcome!", "Hello") and Run, to make sure that you have PythonScript working – doing that pops up the message box for me. If the message box does not pop up, then you have a problem with PythonScript plugin talking with the DLL you copied.

                                      It might look something like:

                                      Python 2.7.18 (v2.7.18:8d21aa21f2, Apr 20 2020, 13:25:05) [MSC v.1500 64 bit (AMD64)]
                                      Initialisation took 687ms
                                      Ready.
                                      >>> notepad.messageBox("Welcome!", "Hello")
                                      1
                                      

                                      (I am on PythonScript 1.5.4 because I’m on a pre-8.3 Notepad++)

                                      If that worked, then use Plugins > Python Script > Scripts > xxx to run your hello-world. Look in the console to see if it gives any error messages.

                                      John Doe 1J 2 Replies Last reply Reply Quote 1
                                      • John Doe 1J
                                        John Doe 1 @Alan Kilborn
                                        last edited by

                                        @alan-kilborn Yeah, I am trying to create a Sorting plugin because I work lots of CSV files. I need a Sort plugin that can single out a field and sort the CSV by that field, I’m sure you can imagine how extremely helpful Pandas would be for that.

                                        Michael VincentM 1 Reply Last reply Reply Quote 3
                                        • John Doe 1J
                                          John Doe 1 @PeterJones
                                          last edited by

                                          @peterjones Thanks for the help, I followed your suggestions and I did get a message box to pop up, when I tried running my Script nothing happens again, no errors in the console show up either.

                                          I grabbed the Python27.dll from my System32 folder, I previously had Python 3.1 installed and then installed Python 2.7. Is it possible the dll I pulled from System32 may have been for Python 3.1? I am a bit confused with the history of that file.

                                          1 Reply Last reply Reply Quote 0
                                          • Michael VincentM
                                            Michael Vincent @John Doe 1
                                            last edited by

                                            @john-doe-1 said in Adding Libraries to PythonScript Plugin:

                                            Yeah, I am trying to create a Sorting plugin because I work lots of CSV files. I need a Sort plugin that can single out a field and sort the CSV by that field,

                                            If you’re using the latest Notepad++ 8.3, then this won’t work, but if you’re on an older version - you should look at CsvQuery plugin. It puts CSV files into a SQL database that you can run any SQL commands on and even rewrite the CSV with the output.

                                            It still needs to be updated for Notepad++ >= 8.3 - see issue.

                                            Cheers.

                                            John Doe 1J 1 Reply Last reply Reply Quote 1
                                            • First post
                                              Last post
                                            The Community of users of the Notepad++ text editor.
                                            Powered by NodeBB | Contributors