Updated Notepad++ today from a far-downrev version (5.4?) to 6.6.9. In the plugin manager, there were no plugins installed, so I selected the current PythonScript (1.0.6) and installed it. All my existing scripts showed up in the menu (without shortcuts, altho I'm not 100% sure the shortcuts were set up for them before). But they don't work.
I can open the PythonScript console and do simple assignments and prints, so I guess it's installed OK; but none of the scripts on the menu -- e.g. editor.addText('\r\n') -- do anything; nor do the same commands on the editor typed into the console.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
on the console? The fact you can print at all shows most things are
working, so I can't really see what's missing. I'd compare your startup.py
under notepad++\plugins\pythonscript\scripts to the official one (see
github.com/davegb3/PythonScript - sorry I've not got the full path with me)
, it sounds like something in there is not right.
Dave
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Dave: that works, it puts the 'hello world' text into the buffer, and prints 0 to the console. The other commands I tried print nothing to console, unless I explicitly print or type a literal or variable.
My scripts don't import anything, and don't qualify 'editor' with the 'Npp' prefix - is that a (recent) requirement?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In the %PROGRAMFILES%\Notepad++\plugins\PythonScript folder, startup.py has that line. There are hundreds of scripts; there are some .pyd files which indicates they have been found at some point since I installed. (Or maybe not: the file date on those PYDs is the same as the PYs. )No startup.pyd, tho.
In my %APPDATA%\Notepad++\plugins\config\PythonScript folder there is nothing but a scripts subfolder, which contains the scripts I've written. The names of these appear in the Plugins menu.
When I start Notepad++ and open the console, it seems neither Npp nor editor are available as top-level symbols; and no Python errors (tracebacks) appear at all (neither red nor black) in the console.
If I explicitly import Npp, I can then access Npp.editor.
I've got the Init configuration set to "ATSTARTUP".
Also: I had a startup.py in my profile (APPDATA) scripts, which used to work and no longer does. I renamed it and restarted, but the same problem with the global startup.py not executing persists.
Last edit: Mike Cowperthwaite 2014-09-10
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
OK, so I copied the default PythonScript startup.py to my profile's scripts folder, and now from the console the Npp symbols have been imported: I can type 'editor' and I see repr(Npp.editor); and I now see error messages in red.
First: This didn't used to be necessary: when I first started using PythonScript, it loaded the %PROGRAMFILES% startup.py first and then the %APPDATA% one.
Second: even with the Npp symbols in place, my scripts are not working. And if I try to import a script from the console, it complains that 'editor' is not defined, even tho the console window knows it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I remember having similar problems. Did you solve yours?
A few ideas:
Check if you have Python27 installed as well, you may have a conflict. Try renaming the installation folder so it cannot be "found" and try again!?
Did you install the "extra libraries" with Python Script?
Good luck.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I do have Python2.7 installed on my system, but there are no Python hooks in any of the system variables (PATH or PATHEXT).
I tried renaming the system Python directory, and with that, starting Notepad++ shows an "Unknown exception" messagebox.
PythonScript's configuration dialog has a "prefer installed python" checkbox, which was unchecked. With the Python directory renamed, I tried checking it and restarting, then unchecking and restarting; same exception in both cases.
Then I reset the Python directory name, and started Notepad++ with "prefer installed python" checked, and still cannot get my scripts to load.
I don't know what you mean by the "extra libraries" with PythonScript. I just selected the plugin from Plugin Manager and let it install with whatever defaults it uses.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Let me first state that I don't have in-depth knowledge of Python.
You proved that Python2.7 files somehow do get accessed by you current configuration, probably before the NPP files. Of course it should not! Many function files have the same name but slightly different contents. I submitted a ticket last year because I had to 'disable' the Python27 folder in order to run PythonScript but never got any reply... (I forget if I submitted it in NPP or PythonScript sections)
Try PythonScript_1.0.7.0.msi which has an option for "extra libraries". On my side, I selected the option and now have Python27 and NPP6.6.9/PythonScript 1.0.7 all active. Yet I routinely many 'strange bugs' in PythonScript which require long hours to identify...
You may also consider "reshuffling the cards" i.e. remove/reboot/reinstall NPP/Plugins/Python27, the usual way to solve many of Windows miseries!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
at the top, otherwise the variables aren't there, that's just how python works.
You get a new "scope" (that's almost definitely the wrong terminology - i suspect the right terminology is "namespace", but that's used for different things in python 2 and 3, so I'm being cautious :) for each imported script.
When you click a script from the menu, you get the same scope as the console. If you import, you get a new one. This is to stop you overwriting variables in an imported script without knowing about it.
If your scripts that are directly executed use editor/notepad, they should work, if they're imported from the scripts that are run, then you need the from Npp import *
I'll investigate the startup script issue when I get chance - it should work as you say, in that first the system startup.py, then the user.
Dave.
PS. Note that this isn't to do with a pre-installed python, those issues should all be resolved as of 1.0.0.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
OK, so what I'm reading here is that, in the console, doing an explicit "import" of one of my scripts isn't supposed to work unless the script imports Npp. That's fine, because I don't usually want to do that anyway.
Here's a thought about the access to system scripts: does the user need write access to the script directory? Because I have my system locked down to prevent non-admin writes to %PROGRAMFILES%, and I don't run Notepad++ as Admin.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm replying inline using email, so apologies if the formatting is off.
OK, so what I'm reading here is that, in the console, doing an explicit
"import" of one of my scripts isn't supposed to work unless the script
imports Npp.
Exactly right.
Here's a thought about the access to system scripts: does the user need
write access to the script directory? Because I have my system locked down
to prevent non-admin writes to %PROGRAMFILES%, and I don't run Notepad++ as
Admin.
No, you don't need write access. If the user does have write access, python
will write a ".pyc" file for each imported script - this is a "compiled"
version of the file, and means it simply runs quicker next time. Note it
doesn't matter if the user can't create the file, it's simply not created,
and there's no speed up for the second run (python has to read and parse
the .py file each time). Also note that it only writes the .pyc file for
imported scripts, and never for scripts that are simply run from N++.
Hope that helps,
Dave
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I saw there was an update, so I removed PythonScript 1.0.6 using Plugin Manager (which is how I'd installed it), restarted, ran the PS1.0.8 msi file (with 'extra libraries' selected per Kadner's suggestions), and reset the startup.py in my %APPDATA% folder to its original configuration.
I am now seeing that the console recognizes 'editor' so the %PROGRAMFILES% startup.py is being run; and, the startup.py in %APPDATA% is also being run (it tweaks the margins in the Scintilla views). This is an improvement over the original report.
But, my individual script files are still not executing. I can enter the code from the one-line scripts in the console and that works fine, but I can't execute the scripts. They do show up in the menus.
Configuration has "Initialisation" = ATSTARTUP and "Prefer installed libraries" CHECKED.
I'm not even sure how to debug this any further.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
That sounds like there's an error in your script, and the error isn't getting printed on the console.
On the console, can you try adding just the following to a normal script, then running that script. Then, try running your script that normally doesn't execute.
importsyssys.stderr=consoleconsole.write('Set stderr to console')
The console always temporarily sets stdout and stderr to the console while console commands run, but they are reset to their original values afterwards, which may explain why console commands work but your scripts don't. (It also explains why you can't set sys.stderr in the console, it will always be reset after the command is run)
I presume you're using "Prefer installed libraries" because you've got a python 2.7 version installed - if you do this, you should copy the python27.dll from your python installation to the Notepad++ folder, overwriting the bundled version. Otherwise, this could be the error (it may try and load a standard binary library that is incompatible with the bundled python27.dll) . If you've not got a python27 installed, or you're not sure, I'd untick the prefer installed libraries and restart N++.
Dave.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
OK, I have solved the problem. The configuration file was copied from a different machine. The path to scripts was subtly different, as I had a different username on that original machine. This was not obvious, in part because the displayed paths in the "Menu" box are compacted and unable to be expanded in the configuration dialog.
Why no error displayed anywhere when SCRIPT FILE NOT FOUND? This seems a glaring omission.
And why are those paths elliptified to fit a width rather less than that of the entire box, when there is a horizontal scroller in the box as well?
Anyway, on removing all the old Menu items and re-adding them, my scripts work fine now.
BTW, I had "prefer installed libraries" as hangover from earlier debugging, it's unchecked now.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes, that the script doesn't exist should definitely report an error. I'll fix that in the next version (it wasn't a glaring omission, as it's not something that's ever come up before).
PythonScript itself doesn't do any elliptification (is that even a word?!?), it's just left up to the windows APIs, so I'm not sure why it would shorten a path.
Cheers,
Dave.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Updated Notepad++ today from a far-downrev version (5.4?) to 6.6.9. In the plugin manager, there were no plugins installed, so I selected the current PythonScript (1.0.6) and installed it. All my existing scripts showed up in the menu (without shortcuts, altho I'm not 100% sure the shortcuts were set up for them before). But they don't work.
I can open the PythonScript console and do simple assignments and prints, so I guess it's installed OK; but none of the scripts on the menu -- e.g. editor.addText('\r\n') -- do anything; nor do the same commands on the editor typed into the console.
Can you try
on the console? The fact you can print at all shows most things are
working, so I can't really see what's missing. I'd compare your startup.py
under notepad++\plugins\pythonscript\scripts to the official one (see
github.com/davegb3/PythonScript - sorry I've not got the full path with me)
, it sounds like something in there is not right.
Dave
Dave: that works, it puts the 'hello world' text into the buffer, and prints 0 to the console. The other commands I tried print nothing to console, unless I explicitly print or type a literal or variable.
My scripts don't import anything, and don't qualify 'editor' with the 'Npp' prefix - is that a (recent) requirement?
No, it's not a recent requirement. It's always been in the startup.py, it
sounds like that's missing from your startup.py - compare yours to
https://github.com/davegb3/PythonScript/blob/master/scripts/startup.py
You just need the
in there somewhere near the top.
Dave, have you given up on me?
No, he's just been at jsconfeu (http://2014.jsconf.eu/) all week and likely isn't back yet ( or at least not back in this game - or world - yet. )
C'mon, Big Dave... time to think in Python again... ;-)
In the %PROGRAMFILES%\Notepad++\plugins\PythonScript folder, startup.py has that line. There are hundreds of scripts; there are some .pyd files which indicates they have been found at some point since I installed. (Or maybe not: the file date on those PYDs is the same as the PYs. )No startup.pyd, tho.
In my %APPDATA%\Notepad++\plugins\config\PythonScript folder there is nothing but a scripts subfolder, which contains the scripts I've written. The names of these appear in the Plugins menu.
When I start Notepad++ and open the console, it seems neither Npp nor editor are available as top-level symbols; and no Python errors (tracebacks) appear at all (neither red nor black) in the console.
If I explicitly import Npp, I can then access Npp.editor.
I've got the Init configuration set to "ATSTARTUP".
Also: I had a startup.py in my profile (APPDATA) scripts, which used to work and no longer does. I renamed it and restarted, but the same problem with the global startup.py not executing persists.
Last edit: Mike Cowperthwaite 2014-09-10
OK, so I copied the default PythonScript startup.py to my profile's scripts folder, and now from the console the Npp symbols have been imported: I can type 'editor' and I see repr(Npp.editor); and I now see error messages in red.
First: This didn't used to be necessary: when I first started using PythonScript, it loaded the %PROGRAMFILES% startup.py first and then the %APPDATA% one.
Second: even with the Npp symbols in place, my scripts are not working. And if I try to import a script from the console, it complains that 'editor' is not defined, even tho the console window knows it.
I remember having similar problems. Did you solve yours?
A few ideas:
Check if you have Python27 installed as well, you may have a conflict. Try renaming the installation folder so it cannot be "found" and try again!?
Did you install the "extra libraries" with Python Script?
Good luck.
I do have Python2.7 installed on my system, but there are no Python hooks in any of the system variables (PATH or PATHEXT).
I tried renaming the system Python directory, and with that, starting Notepad++ shows an "Unknown exception" messagebox.
PythonScript's configuration dialog has a "prefer installed python" checkbox, which was unchecked. With the Python directory renamed, I tried checking it and restarting, then unchecking and restarting; same exception in both cases.
Then I reset the Python directory name, and started Notepad++ with "prefer installed python" checked, and still cannot get my scripts to load.
I don't know what you mean by the "extra libraries" with PythonScript. I just selected the plugin from Plugin Manager and let it install with whatever defaults it uses.
Let me first state that I don't have in-depth knowledge of Python.
You proved that Python2.7 files somehow do get accessed by you current configuration, probably before the NPP files. Of course it should not! Many function files have the same name but slightly different contents. I submitted a ticket last year because I had to 'disable' the Python27 folder in order to run PythonScript but never got any reply... (I forget if I submitted it in NPP or PythonScript sections)
Try PythonScript_1.0.7.0.msi which has an option for "extra libraries". On my side, I selected the option and now have Python27 and NPP6.6.9/PythonScript 1.0.7 all active. Yet I routinely many 'strange bugs' in PythonScript which require long hours to identify...
You may also consider "reshuffling the cards" i.e. remove/reboot/reinstall NPP/Plugins/Python27, the usual way to solve many of Windows miseries!
Sorry for the delay in reply.
If you import a script, you need to do the
at the top, otherwise the variables aren't there, that's just how python works.
You get a new "scope" (that's almost definitely the wrong terminology - i suspect the right terminology is "namespace", but that's used for different things in python 2 and 3, so I'm being cautious :) for each imported script.
When you click a script from the menu, you get the same scope as the console. If you import, you get a new one. This is to stop you overwriting variables in an imported script without knowing about it.
If your scripts that are directly executed use editor/notepad, they should work, if they're imported from the scripts that are run, then you need the
from Npp import *
I'll investigate the startup script issue when I get chance - it should work as you say, in that first the system startup.py, then the user.
Dave.
PS. Note that this isn't to do with a pre-installed python, those issues should all be resolved as of 1.0.0.
OK, so what I'm reading here is that, in the console, doing an explicit "import" of one of my scripts isn't supposed to work unless the script imports Npp. That's fine, because I don't usually want to do that anyway.
Here's a thought about the access to system scripts: does the user need write access to the script directory? Because I have my system locked down to prevent non-admin writes to %PROGRAMFILES%, and I don't run Notepad++ as Admin.
I'm replying inline using email, so apologies if the formatting is off.
Exactly right.
No, you don't need write access. If the user does have write access, python
will write a ".pyc" file for each imported script - this is a "compiled"
version of the file, and means it simply runs quicker next time. Note it
doesn't matter if the user can't create the file, it's simply not created,
and there's no speed up for the second run (python has to read and parse
the .py file each time). Also note that it only writes the .pyc file for
imported scripts, and never for scripts that are simply run from N++.
Hope that helps,
Dave
I saw there was an update, so I removed PythonScript 1.0.6 using Plugin Manager (which is how I'd installed it), restarted, ran the PS1.0.8 msi file (with 'extra libraries' selected per Kadner's suggestions), and reset the startup.py in my %APPDATA% folder to its original configuration.
I am now seeing that the console recognizes 'editor' so the %PROGRAMFILES% startup.py is being run; and, the startup.py in %APPDATA% is also being run (it tweaks the margins in the Scintilla views). This is an improvement over the original report.
But, my individual script files are still not executing. I can enter the code from the one-line scripts in the console and that works fine, but I can't execute the scripts. They do show up in the menus.
Configuration has "Initialisation" = ATSTARTUP and "Prefer installed libraries" CHECKED.
I'm not even sure how to debug this any further.
That sounds like there's an error in your script, and the error isn't getting printed on the console.
On the console, can you try adding just the following to a normal script, then running that script. Then, try running your script that normally doesn't execute.
The console always temporarily sets stdout and stderr to the console while console commands run, but they are reset to their original values afterwards, which may explain why console commands work but your scripts don't. (It also explains why you can't set sys.stderr in the console, it will always be reset after the command is run)
I presume you're using "Prefer installed libraries" because you've got a python 2.7 version installed - if you do this, you should copy the python27.dll from your python installation to the Notepad++ folder, overwriting the bundled version. Otherwise, this could be the error (it may try and load a standard binary library that is incompatible with the bundled python27.dll) . If you've not got a python27 installed, or you're not sure, I'd untick the prefer installed libraries and restart N++.
Dave.
OK, I have solved the problem. The configuration file was copied from a different machine. The path to scripts was subtly different, as I had a different username on that original machine. This was not obvious, in part because the displayed paths in the "Menu" box are compacted and unable to be expanded in the configuration dialog.
Why no error displayed anywhere when SCRIPT FILE NOT FOUND? This seems a glaring omission.
And why are those paths elliptified to fit a width rather less than that of the entire box, when there is a horizontal scroller in the box as well?
Anyway, on removing all the old Menu items and re-adding them, my scripts work fine now.
BTW, I had "prefer installed libraries" as hangover from earlier debugging, it's unchecked now.
Yes, that the script doesn't exist should definitely report an error. I'll fix that in the next version (it wasn't a glaring omission, as it's not something that's ever come up before).
PythonScript itself doesn't do any elliptification (is that even a word?!?), it's just left up to the windows APIs, so I'm not sure why it would shorten a path.
Cheers,
Dave.