libreoffice-code-highlighter icon indicating copy to clipboard operation
libreoffice-code-highlighter copied to clipboard

A Scripting Framework error occurred while executing the Python script

Open pafpm opened this issue 6 years ago • 47 comments

It seems I installed correctly the Code Highlighter. I followed all steps on installation. But when I select the text on Impress and choose to highlight a Python code, the following error happens:

A Scripting Framework error occurred while executing the Python script vnd.sun.star.script:codehighlighter.oxt|python|highlight.py$highlight_python3_default?language=Python&location=user:uno_packages.

Mensagem: <class 'KeyError'>: 'codehighlighter.oxt' File "/usr/lib/libreoffice/program/pythonscript.py", line 993, in getScript self.provCtx.uriHelper.getStorageURI(scriptUri) ); File "/usr/lib/libreoffice/program/pythonscript.py", line 381, in getStorageUrlFromPersistentUrl package = self.mapPackageName2Path[ packageName ]

pafpm avatar Aug 31 '18 18:08 pafpm

Same here. My system:

  • Ubuntu 18.04 LTS
  • Libreoffice:

Version: 6.0.6.2 Build-ID: 1:6.0.6-0ubuntu0.18.04.1 CPU-Threads: 4; BS: Linux 4.15; UI-Render: Standard; VCL: gtk3; Gebietsschema: de-DE (de_DE.UTF-8); Calc: group

  • Python 3.6.6
  • pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)
  • Pygments (2.2.0) [installed with pip3 like the documentation]

Schweineschwarte avatar Nov 02 '18 15:11 Schweineschwarte

Same here: Ubuntu 16.04 LTS LibreOffice 5.4.6.2 40m0(Build:2)

ii  libreoffice                                   1:5.4.6~rc2-0ubuntu0.16.04. amd64                       office productivity suite (metapackage)
ii  libreoffice-script-provider-python            1:5.4.6~rc2-0ubuntu0.16.04. all                         Python script support provider for LibreOffice scripting framework
ii  python3-pygments                              2.1+dfsg-1                  all                         syntax highlighting package written in Python 3

jove1 avatar Dec 10 '18 13:12 jove1

Same here: Ubuntu 18.10 Libreoffice 6.1.3

samyon196 avatar Dec 16 '18 22:12 samyon196

Please check the latest release v1.5.

slgobinath avatar Jan 28 '19 20:01 slgobinath

Same here (with v1.5) Linux Mint 18.1 LO: 6.1.4.2

JoseOlin avatar Jan 30 '19 07:01 JoseOlin

@JLuisGT could you please give some more information?

  1. Does it occur only in LO Impress or in Writer too?
  2. Does it occur when you select a code and try to highlight or when you select the text box (as given in How to use and try to highlight?
  3. Could you please share the screenshot of the error message?

slgobinath avatar Jan 30 '19 11:01 slgobinath

Hi @slgobinath It's very attentive of you to answer this fast!

  1. It happens in both Impress and Writer.

  2. It happens both, selecting the code AND selecting a text box with the code inside.

  3. For sure! Impress Error Writer error

JoseOlin avatar Jan 31 '19 00:01 JoseOlin

Hi, May I know how you installed the extension? Did you install it only for the current user or for all users?

slgobinath avatar Jan 31 '19 03:01 slgobinath

Hi, @slgobinath

I don't really know. I just close all the LO products and make the Ubuntu derivatives installation, as recommended.

$ sudo apt-get install libreoffice-script-provider-python
$ sudo pip3 install pygments

How can I check if I made a current or all users installation?

Best regards.

JoseOlin avatar Feb 01 '19 21:02 JoseOlin

Hi, Though I couldn't reproduce this error, it affects other platforms as well: #25, #26, #28

@ruben1981 fixed the problem by copying the pygments folder to /usr/lib/libreoffice/program folder. You can find the location of pygments module by running the following code in Python 3:

import pygments
print(pygments.__file__)

In my case the output is /usr/local/lib/python3.6/dist-packages/pygments/__init__.py.

To copy this module, enter the following command:

sudo cp -r /usr/local/lib/python3.6/dist-packages/pygments /usr/lib/libreoffice/program/

slgobinath avatar Feb 02 '19 14:02 slgobinath

Hi, @slgobinath

I try your suggestion without luck. In my case pygments is in /usr/lib/python3/dist-packages/pygments.

Just as a note: I also try refreshing the user profile, giving that another extension (TexMaths) wasn't working as well. After the refreshing, TexMaths is working but no luck with this handy extension.

I'll keep trying and thanks a lot for your patience.

JoseOlin avatar Feb 03 '19 06:02 JoseOlin

When you install the extension did you get the option to install it for only you or for all users? If so, please install it only for you and see if it works.

In my case, I am using LM 19.1 and LO 6.0.7.3 with no problem. I will give a try with the latest LO and let you know.

slgobinath avatar Feb 03 '19 12:02 slgobinath

I am commenting for myself because I am hitting this issue over again, if text is selected instead of container it will crash. So I guess if there is no container selected but some text, the script should resolve to current container before processing.

rzr avatar Mar 18 '19 18:03 rzr

[SOLVED] In the documentation, it was written to install the following packages: $ sudo apt-get install libreoffice-script-provider-python $ sudo pip3 install pygments

If you are still getting the error, try installing 'python3-pygments': $sudo apt install python3-pygments

tronifier avatar Mar 26 '19 17:03 tronifier

Hi! First: Thanks for this cool extension! Second: Error described here occurs if you download extension many times and install it from the file like codehighlighter-1.oxt or codehighlighter (1).oxt . Note original name is codehighlighter.oxt. In the Framework code occurs search by extension name, and in first case name are wrong. Framework cannot find extension with name codehighlighter-1.oxt. Simply solutions is reinstall plugin from file codehighlighter.oxt

Have a good day!

sakateka avatar May 15 '19 08:05 sakateka

I also have the same error: image on Windows 10, x64, libreoffice 6.1.5.2 and I install the extension using codehighlighter.oxt file.

silviulaurentiu avatar Jun 06 '19 17:06 silviulaurentiu

SOLVED (WINDOWS 10)

Go to --> "C:\Users\ {Your Username} \AppData\Local\Programs\Python\Python37\Lib\site-packages" And copy "pygments" and "Pygments-2.4.2.dist-info" folders. Now go to ---> "C:\Program Files\LibreOffice\program\python-core-3.5.7\lib\site-packages" And paste both of these folders here.

That's it, Done.

DevRThakkar avatar Aug 02 '19 05:08 DevRThakkar

On Ubuntu 18.04, I managed to fix the issue by installing LibreOffice with apt-get instead of snap. Not sure what the issue was or if it was even related to that, but it might be worth a try.

KasperFyhn avatar Aug 31 '19 09:08 KasperFyhn

I had the same issue but it was solved once I installed python3-pygments, python3-pip, etc. using sudo apt install package

therayvoice avatar Oct 07 '19 09:10 therayvoice

Hi, May I know how you installed the extension? Did you install it only for the current user or for all users?

hello @slgobinath I had issues similar to @JLuisGT . At first I installed the extension for all users and encountered this error. However, after removing the extension and then installing it for current user solved my problem. But before that I copied pygments folder to ..\LibreOffice\program\python-core-3.5.7\lib\site-packages

Mohaymin avatar Oct 20 '19 07:10 Mohaymin

I also have the same error: image on Windows 10, x64, libreoffice 6.1.5.2 and I install the extension using codehighlighter.oxt file.

Similar, with Version: 6.3.3.2 (x64) Build ID: a64200df03143b798afd1ec74a12ab50359878ed Threads CPU : 4; OS : Windows 10.0; UI Render : par défaut; VCL: win; Locale : fr-CH (fr_FR); Langue IHM : fr-FR Calc: threaded

droumanet avatar Nov 01 '19 16:11 droumanet

Can't contribute much to this issue right now. I've had the same troubles however and just documenting what I've done so far.

A short note about installing Pygments from Debian repositories, or the likes, is that it will probably be a much older version of Pygments than is available with pip, so maybe pip3 install pygments is better than apt install python3-pygments.

Anyway, the following creates the failures: installing codehighlighter with sudo unopkg gui --shared and then installing it for all users, then trying to tun the extension raises the error. Also running libreOffice as root raises the same error. Installing it for one user does the same. Adding it in normal ways... well, i've tried numerous combinations and always manage to get the error. Also having a textbox or not etc eems to not influence the issue.

With DEBUG in pythonloader.py and pythonscript.py this is the error when starting Writer to then using the extension:

Sat Nov  9 19:43:57 2019 [DEBUG] inspecting package codehighlighter.oxt(javahelps.codehighlighter)
Sat Nov  9 19:43:57 2019 [ERROR] adding Package lu5379rx1ckq.tmp_ ('file:///var/spool/libreoffice/uno_packages/cache/uno_packages/lu5379rx1ckq.tmp_/codehighlighter.oxt/python',)

...

Sat Nov  9 19:44:30 2019 [DEBUG] getScript vnd.sun.star.script:codehighlighter.oxt|python|highlight.py$create_dialog?language=Python&location=user:uno_packages invoked
Sat Nov  9 19:44:30 2019 [DEBUG] converting scriptURI=vnd.sun.star.script:codehighlighter.oxt|python|highlight.py$create_dialog?language=Python&location=user:uno_packages to storageURI=file:///home/user/.config/libreoffice/4/user/uno_packages/cache/uno_packages/codehighlighter.oxt/python/highlight.py$create_dialog
Sat Nov  9 19:44:30 2019 [ERROR] <class 'KeyError'>: 'codehighlighter.oxt'
  File "/usr/lib/libreoffice/program/pythonscript.py", line 1052, in getScript
    self.provCtx.uriHelper.getStorageURI(scriptUri) );
  File "/usr/lib/libreoffice/program/pythonscript.py", line 422, in getStorageUrlFromPersistentUrl
    package = self.mapPackageName2Path[ packageName ]

The following is debug output when adding the extension. This is from the unopkg gui program when extension is not installed through to it apparently being "installed":

ERROR: (com.sun.star.lang.IllegalArgumentException) { { { Message = "There is no such extension deployed: javahelps.codehighlighter", Context = (com.sun.star.uno.XInterface) @588a8d52a5a0 } }, ArgumentPosition = (short) -1 }

pythonloader.Loader ctor
pythonloader.Loader.activate
pythonloader: interpreting url vnd.openoffice.pymodule:pythonscript
pythonloader: after expansion vnd.openoffice.pymodule:pythonscript
Sat Nov  9 19:54:13 2019 [DEBUG] pythonscript loading
Sat Nov  9 19:54:13 2019 [DEBUG] pythonscript finished initializing
Fetched ImplHelper as <unohelper.ImplementationHelper object at 0x7f73c4491e10>
Sat Nov  9 19:54:13 2019 [DEBUG] Entering PythonScriptProvider.ctorshare:uno_packages
Sat Nov  9 19:54:13 2019 [DEBUG] initialized urihelper with baseUri=file:///var/spool/libreoffice/uno_packages/cache/uno_packages,m_scriptUriLocation=share:uno_packages
Sat Nov  9 19:54:13 2019 [DEBUG] got urlHelper <pythonscript.MyUriHelper object at 0x7f73c4454b00>
Sat Nov  9 19:54:13 2019 [DEBUG] share:uno_packages transformed to file:///var/spool/libreoffice/uno_packages/cache/uno_packages
Sat Nov  9 19:54:13 2019 [DEBUG] pythonscript: getPackageName2PathMap start getDeployedPackages
Sat Nov  9 19:54:13 2019 [DEBUG] pythonscript: getPackageName2PathMap end getDeployedPackages (1)
Sat Nov  9 19:54:13 2019 [DEBUG] inspecting package codehighlighter.oxt(javahelps.codehighlighter)
Sat Nov  9 19:54:13 2019 [ERROR] adding Package lu5744rxgwow.tmp_ ('file:///var/spool/libreoffice/uno_packages/cache/uno_packages/lu5744rxgwow.tmp_/codehighlighter.oxt/python',)
Sat Nov  9 19:54:13 2019 [DEBUG] hasByName called vnd.sun.star.expand:$UNO_SHARED_PACKAGES_CACHE/uno_packages/lu5744rxgwow.tmp_/codehighlighter.oxt/python
Sat Nov  9 19:54:13 2019 [DEBUG] hasByName file:///var/spool/libreoffice/uno_packages/cache/uno_packages/lu5744rxgwow.tmp_/codehighlighter.oxt/python True

Reading the thread it seems that various combinations of copying pygments around manually or installing extension globally or for only single user will make the problem go away. Anyone have any further ideas, or where to look for clues?

pip 18.1-5 Pygments 2.4.2 libreoffice (debian) 1:6.3.3-2~bpo10+1 (VLC is GTK3) libreoffice-script-provider-python 1:6.3.3-2~bpo10+1 (installed automatically as dependency) Linux 4.19, Debian 10 OpenJDK Runtime Environment (build 11.0.5+10-post-Debian-1deb10u1)

weleoka avatar Nov 09 '19 18:11 weleoka

After more research I find that this is most likely to do with the maintainer not wanting to maintain two versions of the extension for all users and only installed for single user.

There is an extensive discussion on this at: Document Foundation Bug #100307. It is essentially an added workload to make the Addons.xcu file compatible with all or individual users.

It also seems to be an issue worsened by a bug in the libreoffice core that isn't quite pinned down as yet.... because ideally core or Unopkg should warn about this in a friendly way.

To install this extension and use it - this is the process that worked for me:

sudo install python3-pip
sudo pip3 install pygments
unopkg gui
# Add the .oxt file and only for single current user if asked

Then it should work. Good luck.

weleoka avatar Nov 11 '19 12:11 weleoka

On Ubuntu 18.04, I managed to fix the issue by installing LibreOffice with apt-get instead of snap. Not sure what the issue was or if it was even related to that, but it might be worth a try.

I agree you, i've searched tons of web pages but only this comment solved my problem. Thank you :)

mertdot avatar Apr 01 '20 19:04 mertdot

Hi! First: Thanks for this cool extension! Second: Error described here occurs if you download extension many times and install it from the file like codehighlighter-1.oxt or codehighlighter (1).oxt . Note original name is codehighlighter.oxt. In the Framework code occurs search by extension name, and in first case name are wrong. Framework cannot find extension with name codehighlighter-1.oxt. Simply solutions is reinstall plugin from file codehighlighter.oxt

Have a good day!

For me the solving hint. It was not because of downloading it multiple times, but download file had an additional prefix: ea4db15f_codehighlighter.oxt. After renaming it works on my system.

yneuma avatar May 28 '20 09:05 yneuma

Maybe this error popup should display a link to this ticket :)

rzr avatar May 28 '20 10:05 rzr

Kudos to @yneuma , renaming the extension fixed it for me on my Fedora 32 system. I'd tried manually copying the pygments folder etc, but it turns out the default filename of the package after you download it from the extensions website is the problem.

So get rid of the ea4db15f_ in the package filename...

ArenT1981 avatar May 29 '20 21:05 ArenT1981

I have no idea why this happens (the lookup should be based on internal extension name, not installation filename), but I can confirm that the renaming fixes it. I had a non-working install, and:

  1. Renamed the file in my /tmp/mozilla_username0/ folder to remove the prefix.
  2. Removed the extension from LibreOffice Writer.
  3. Double-clicked on the extension in pcmanfm.
  4. Clicked "install".
  5. Clicked "accept".
  6. Restarted LibreOffice Writer.

And it worked, all of a sudden. Nothing else in my system changed.

wizzwizz4 avatar Jun 24 '20 12:06 wizzwizz4

Renaming the installation file solved the scripting framework error for me too. This should probably make its way into the installation instructions on the Extension page ;)

william-e avatar Jul 02 '20 13:07 william-e

Renaming the installation file worked for me!

alvaro1553 avatar Jul 04 '20 14:07 alvaro1553