Adding Libraries to PythonScript Plugin
-
I don’t know that this forum is the place for obtaining help on installing non-Notepad++ related Python components.
-
@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. Usepip
(Python package management) to install them properly for your distribution.Cheers.
-
@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.
-
@alan-kilborn I can install components on PyCharm, the issue is getting them to work with the PythonScript environment within Notepad++.
-
@michael-vincent By the way this is the Pandas folder I dropped into lib,
-
@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.
-
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 thePythonScript\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 usepip
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 withpip
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 thePythonScript\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
- 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 thec:\Windows\
directory (or equivalent location on your configuration).- or if you have some other version, let us know.
- 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 theNotepad++\plugins\PythonScript
folder - 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)
- 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. - 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.
- 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
-
This post is deleted! -
@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?
-
@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.
-
@peterjones Okay I finally got Windows to recognize my Python version and installed pandas:
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 pandasForSortingCSVnotepad.messageBox(“Welcome!”, “Welcome!”)
notepad.messageBox(“Hello!”, “Hello!”) -
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-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, writenotepad.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.
-
@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.
-
@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.
-
@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.
-
@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?
-
@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.
-
@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.
-
@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.