No module named Npp
-
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?
-
@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() -
Well, from the error message I’d assume that you put
console.write()
directly in your code. What I mean was to put something likeconsole.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.
-
@Alan-Kilborn Okay, will do! Thank you again!
-
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
-
-
@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.
-
@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.
-
@Alan-Kilborn @guy038 Issue fixed. Changed
filePathSrc= "some directory"
tofilePathSrc= r"somedirectory"
and everything worked fine. -
Of course, we could have never debugged THAT from here. :)
-
@Alan-Kilborn yep :) well, thanks for your help!