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 @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
                      • John Doe 1J
                        John Doe 1 @PeterJones
                        last edited by

                        @peterjones By the way I am using version 2.7.16 because it is recommended , is that okay as long as it is in the 2.7.X versions? Or does it have to be 2.7.0 specifically?

                        pandas4.png

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

                          @michael-vincent Thanks for the suggestion but I am gonna keep trying to get this to work so I have something I can update as needed, I wish I could get Pandas to work, that’s really the only barrier right now as I have a pretty good idea of how my code is going to function.

                          Michael VincentM 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:

                            as long as it is in the 2.7.X versions? Or does it have to be 2.7.0 specifically?

                            For me on Python3 and the PythonScript v3 train, the major minor version is good enough - reference my earlier post:

                            • System Python = 3.8.10
                            • PythonScript = 3.8.9

                            Cheers.

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

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

                              I wish I could get Pandas to work

                              For me - it’s dead simple:

                              PS VinsWorldcom ~ > python3
                              Python 3.8.10 (tags/v3.8.10:3d8993a, May  3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)] on win32
                              Type "help", "copyright", "credits" or "license" for more information.
                              >>> import pandas
                              Traceback (most recent call last):
                                File "<stdin>", line 1, in <module>
                              ModuleNotFoundError: No module named 'pandas'
                              

                              and PythonScript:

                                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.
                              >>> import pandas
                              Traceback (most recent call last):
                                File "<console>", line 1, in <module>
                              ModuleNotFoundError: No module named 'pandas'
                              

                              So, we install it:

                              PS VinsWorldcom ~ > python3 -mpip install pandas
                              Collecting pandas
                                Downloading pandas-1.4.2-cp38-cp38-win_amd64.whl (10.6 MB)
                                   |████████████████████████████████| 10.6 MB 6.4 MB/s
                              Collecting pytz>=2020.1
                                Downloading pytz-2022.1-py2.py3-none-any.whl (503 kB)
                                   |████████████████████████████████| 503 kB 6.4 MB/s
                              Requirement already satisfied: numpy>=1.18.5 in c:\users\VinsWorldcom\appdata\roaming\python\python38\site-packages (from pandas) (1.19.5)
                              Requirement already satisfied: python-dateutil>=2.8.1 in c:\users\VinsWorldcom\appdata\roaming\python\python38\site-packages (from pandas) (2.8.1)
                              Requirement already satisfied: six>=1.5 in c:\users\VinsWorldcom\appdata\roaming\python\python38\site-packages (from python-dateutil>=2.8.1->pandas) (1.15.0)
                              Installing collected packages: pytz, pandas
                              Successfully installed pandas-1.4.2 pytz-2022.1
                              

                              Now it works:

                              PS VinsWorldcom ~ > python3
                              Python 3.8.10 (tags/v3.8.10:3d8993a, May  3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)] on win32
                              Type "help", "copyright", "credits" or "license" for more information.
                              >>> import pandas
                              >>> print(pandas.__file__)
                              C:\Users\VinsWorldcom\AppData\Roaming\Python\Python38\site-packages\pandas\__init__.py
                              

                              And it now works in PythonScript as well:

                                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.
                              >>> import pandas
                              >>> print(pandas.__file__)
                              C:\Users\VinsWorldcom\AppData\Roaming\Python\Python38\site-packages\pandas\__init__.py
                              

                              You’ll see, it’s finding the same Pandas - from my system Python.

                              Cheers.

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

                                @michael-vincent Thank you for your further assistance, how do you open the Python.exe with this line above it:

                                File “C:\usr\bin\npp64\plugins\Config\PythonScript\scripts\startup.py”, line 1 : PythonScript initialized

                                ?

                                So that I can import packages to that environment

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

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

                                  how do you open the Python.exe with this line above it:

                                  That’s the PythonScript console, menu Plugins => Python Script => Show Console.

                                  60d1d6bc-24a6-4ca6-90cf-f6ec7388a851-image.png

                                  My ‘startup.py’ does some initialization - including printing the file that ran / did the initialization so I can reference it if there is an issue.

                                  Cheers.

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

                                    @michael-vincent Okay I feel very silly, when I first installed Notepad++ and PythonScripts I deleted the Sample scripts along with startup.py, I just put them back where they belong after inspecting your post.

                                    Now my simple test scripts invoking Pandas are at least running, that’s a step foward, I will see if Panda’s functionality works as should.

                                    Thank you very much for the detailed assistance and screenshots, @Michael-Vincent @Alan-Kilborn @PeterJones your help is much appreciated.

                                    :)

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

                                      @michael-vincent Hey I’ve been doing some testing in PyCharm and noticed something strange. I’ve imported pandas and Npp like so:

                                      from Npp import *
                                      import pandas as pandasForSortingCSV

                                      Now with these imports I can read a csv no problem like so:

                                      file = pandasForSortingCSV.read_csv(notepad.getCurrentFilename())

                                      BUT if I try to use the “sort_values” function, nothing happens:

                                      sorted_file = file.sort_values(by=[“Name”], ascending=False, inplace=True)

                                      If I hover over that statement in PyCharm it says:
                                      No documentation found.

                                      Do you happen to have any idea why this might be? The documentation shows that same import supporting the sort_values function so I’m not sure what the issue is. Please let me know if you can think of anything, thank you!

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

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

                                        @michael-vincent Hey I’ve been doing some testing in PyCharm and noticed something strange. I’ve imported pandas and Npp like so:
                                        If I hover over that statement in PyCharm it says:
                                        No documentation found.

                                        Do you happen to have any idea why this might be? The documentation shows that same import supporting the sort_values function so I’m not sure what the issue is. Please let me know if you can think of anything, thank you!

                                        sort_values currently has no doc-string. PyCharm would inspect sort_values and finds no documentation. A comment is in the source # TODO: Just move the sort_values doc here.

                                        Please focus mainly on Notepad++ and PythonScript. This topic is getting very broad if PyCharm issues are included.

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

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

                                          I’ve been doing some testing in PyCharm

                                          WHY?!?!?!

                                          The Npp library won’t work in PyCharm and If you’re trying to manipulate CSV files as I thought you were and not doing it in Notepad++, why are we even talking about Notepad++ and PythonScript. You can easily open files from disk in Python without going through Notepad++ if you’re not even using it.

                                          BUT if I try to use the “sort_values” function, nothing happens:

                                          sorted_file = file.sort_values(by=[“Name”], ascending=False, inplace=True)

                                          No kidding - you didn’t do anything to the file in Notepad++, you just tried to sort the file on disk by opening it by name, not referencing the content of the file in the Notepad++ Scintilla editing component by some method of the editor instance.

                                          If you want to actually sort the file in Notepad++ (and ultimately the one on disk), you need to read the content of the editor object , sort it and write it back.

                                          Maybe have a look at those example scripts that came with PythonScript. Run them. See how they work. Try modifying them a bit to make them do something else before diving headfirst into full file manipulation with pandas.

                                          And please for heavens sake backup all of your data before going any further. I fear this won’t end well.

                                          Cheers.

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

                                            I was only using PyCharm for syntax highlighting and intellisense I know that the Npp library doesn’t work there. I am trying to edit the CSV files in Notepad++

                                            @michael-vincent said in Adding Libraries to PythonScript Plugin:

                                            If you want to actually sort the file in Notepad++ (and ultimately the one on disk), you need to read the content of the editor object , sort it and write it back.

                                            That is what I am trying to do, shouldn’t this line be reading the filename via Notepad. and reading the CSV using read_csv?

                                            file = pandasForSortingCSV.read_csv(notepad.getCurrentFilename())

                                            Alan KilbornA PeterJonesP 2 Replies Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            The Community of users of the Notepad++ text editor.
                                            Powered by NodeBB | Contributors