Zen Coding - Python doesn't work

Help
Trolzen
2012-02-22
2013-01-25
  • Trolzen
    Trolzen
    2012-02-22

    When I select "Expand abbreviation" (or use ctrl+alt+enter) nothing happens. In the python script console this error message appears:

    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    NameError: name 'npp_zen_coding' is not defined

    Plugin was installed this way. I've started Notepad++ under admin, selected Zen coding plugin in plugin manager, clicked "install", agreed to install Python script plugin too, restarted Notepad++ after completion, then exitted Notepad++ and started it under unprivileged user.

    Windows XP SP3 Pro
    Notepad++ 5.9.8
    Python Script 0.9.2
    Zen Coding - Python 0.7.0.1

     
  • Trolzen
    Trolzen
    2012-02-22

    Additionally I can't find any .py files neither in %ProgramFiles% nor in %APPDATA%. Is it OK?

    Under admin user the same error occurs (name 'npp_zen_coding' is not defined).

     
  • Have you got any non-Latin characters in your username?  Python (on windows) struggles with unicode paths for modules - although I thought we'd got that sorted, someone recently had the same problem.  You should have npp_zen_coding.py under %APPDATA%\Notepad++\ZenCodingPython (assuming you're running with config in %APPDATA%, you can check that in the settings dialog in Plugin manager 1.0.8).

    There's a "bug" listed in this project, that isn't really a bug, but explains what to do if you've got extended characters in your username.  See the comments here : https://sourceforge.net/tracker/?func=detail&aid=3475571&group_id=337487&atid=1413747

    I hope that helps - please report back so we can see if we can fix this issue permanentely.
    Dave.

     
  • Trolzen
    Trolzen
    2012-02-26

    My configuration:
    Path to admin profile does contain non-latin characters, since I have localized version of Windows.
    Path to unprivileged user profile does not contain non-latin characters.
    I'm runnig with config in %APPDATA%.

    So here is explanation why the plugin doesn't work in any case. It doesn't work under admin user, because path contains non-latin characters. It doesn't work under unprivileged user, because all python scripts needed by the plugin were written into admin's profile.

    So there are two solutions.

    Soluton #1 (easier). Just copy/move ZenCodingPython folder from %ADMIN_APPDATA%\Notepad++\plugins\config to %APPDATA%\Notepad++\plugins\config.

    Soluton #2 (harder). Move ZenCodingPython folder from %ADMIN_APPDATA%\Notepad++\plugins\config to %PROGRAMFILES%\Notepad++\plugins and apply the provided patch by command patch -p0 < zencoding.patch inside %PROGRAMFILES%\Notepad++ folder.

    --- plugins\PythonScript\scripts\startup.py 2012-02-22 20:36:45.007212800 +0400
    +++ plugins\PythonScript\scripts\startup.py 2012-02-23 17:03:43.289913600 +0400
    @@ -28,4 +28,6 @@
     # will insert "hello world" at the current cursor position of the current document
     sys.stdout = editor
    
    +from os import getenv
    +sys.path.insert(0, getenv('PROGRAMFILES')+r'\Notepad++\plugins\ZenCodingPython')
    

    I've used the latter one. Note that this touches PythonScript plugin, not ZenCoding.

    And the question. Wouldn't it be better to write ZenCodingPython folder into %PROGRAMFILES% during install? I guess it's not a config, but "executable" isn't it?

     
  • For solution 1, you could also just install Zen Coding through plugin manager again as your admin user.

    And the question. Wouldn't it be better to write ZenCodingPython folder into %PROGRAMFILES% during install? I guess it's not a config, but "executable" isn't it?

    That is true.  However, the %PROGRAMFILES% is not normally writable by the user, at least since Vista.  The previous version of the Zen Coding library wrote out a .py file (or needed one writing out, can't remember), with the user abbreviations and snippets in, and that .py file needed to be next to the other Zen files.  The new version uses pickle, which means the user settings file can be separate from the code.  So that's the history, and when I updated to version 0.7, the code wasn't moved.  But there was a reason - moving to a non writable location means that no .pyc files can be written, which would mean compiling the .py every time, which would slow down the startup times even more.  I *think* we could distribute the .pyc's as we (usually) know the exact python version in use, but distributing .pyc's gives me the shivers :)

    Cheers,
    Dave.

     
  • Trolzen
    Trolzen
    2012-02-27

    For solution 1, you could also just install Zen Coding through plugin manager again as your admin user.
    {/quote]This is exaclty the way I installed Zen Coding, which led to disfunction. Or you do you mean I should Install under admin via plugin manager and then reinstall?

    The %PROGRAMFILES% is not writable by users in XP too. But if one use admin user for administrative tasks (installing software, adding plugins) and only for that, which is good practice, it's not a problem.

    May be it's better not to distribute the .pyc's but to generate them during install? As it's done in the python installer. And I think it's definitely need to be done for PythonScript plugin, which has a plenty of .py's in the %PROGRAMFILES%, and .pyc's couldn't be generated for them now. So I think PythonScript affects the performance more than ZenCoding does.