[Solved] APSO No module named 'apso_utils'

Discussions about using 3rd party extension with OpenOffice.org
Post Reply
Bastien
Posts: 61
Joined: Mon May 12, 2014 2:45 pm

[Solved] APSO No module named 'apso_utils'

Post by Bastien »

Just installed ASPO extension. I thought I could then use a normal import from my python macro as following:

Code: Select all

from apso_utils import mri, msgbox
raises the exception "No module named 'apso_utils'" exception.
Did I miss something during the installation? I precise that all my python macro works well. It's just that APSO sounds very handfull.
Last edited by Bastien on Thu Mar 07, 2019 3:46 pm, edited 1 time in total.
LibreOffice 6.2.3.2 on Ubuntu 19.04
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: APSO No module named 'apso_utils'

Post by Villeroy »

Your Python runtime does not know where LibreOffice stores that module. You have to expand your Python path or use some module in your macro directory.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Bastien
Posts: 61
Joined: Mon May 12, 2014 2:45 pm

Re: APSO No module named 'apso_utils'

Post by Bastien »

Sorry but it's not clear to me. Extend my Python path to what? Since it's a python extension, why the path should be added?
LibreOffice 6.2.3.2 on Ubuntu 19.04
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: APSO No module named 'apso_utils'

Post by RoryOF »

The python interpreter needs to know where to look for the apso module. You need to add the location of that module to the path Python uses.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Bastien
Posts: 61
Joined: Mon May 12, 2014 2:45 pm

Re: APSO No module named 'apso_utils'

Post by Bastien »

I use the LO embedded python, so how do I know the path it uses?

Would it be something like :
~/.config/libreoffice/4/user/uno_packages/cache/uno_packages/lu22318xbgt0a.tmp_/apso.oxt/python/pythonpath

It looks weird and complicated.
LibreOffice 6.2.3.2 on Ubuntu 19.04
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: APSO No module named 'apso_utils'

Post by Villeroy »

You may try a link

Code: Select all

ln ~/.config/libreoffice/4/user/uno_packages/cache/uno_packages/lu22318xbgt0a.tmp_/apso.oxt/python/pythonpath ~/.config/libreoffice/4/user/Scripts/python/pythonpath
I use this self made Office class with some of my macros:

Code: Select all

import uno

from com.sun.star.awt.MessageBoxType import MESSAGEBOX, INFOBOX, WARNINGBOX, ERRORBOX, QUERYBOX
from com.sun.star.awt.MessageBoxButtons import BUTTONS_OK, BUTTONS_OK_CANCEL, BUTTONS_ABORT_IGNORE_RETRY, BUTTONS_YES_NO_CANCEL, BUTTONS_YES_NO, BUTTONS_RETRY_CANCEL, DEFAULT_BUTTON_OK, DEFAULT_BUTTON_CANCEL, DEFAULT_BUTTON_RETRY, DEFAULT_BUTTON_YES, DEFAULT_BUTTON_NO, DEFAULT_BUTTON_IGNORE
from com.sun.star.awt.MessageBoxResults import CANCEL, OK, YES, NO, RETRY, IGNORE

class Office:
    '''Frequently used office objects and useful methods'''
    def __init__(self, local_context = uno.getComponentContext(), connect_string = ''):
        if connect_string:
            # "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext"
            resolver = local_context.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", local_context )
            self.ctx = ctx = resolver.resolve(connect_string)
        else:
            self.ctx = local_context
        self.smgr = self.ctx.getServiceManager()
        self.tk = self.smgr.createInstance('com.sun.star.awt.Toolkit')
        self.StarDesktop = self.smgr.createInstance('com.sun.star.frame.Desktop')
        self.win = None

    def getDocument(self):
        return self.StarDesktop.CurrentFrame.Controller.getModel()
        
    def createUnoService(self, name,):
        return self.smgr.createInstance(name)
        
    def getURLStruct(self, sURL):
        url = uno.createUnoStruct('com.sun.star.util.URL')
        srv = self.createUnoService('com.sun.star.util.URLTransformer')
        url.Complete = sURL
        x = uno.invoke(srv,"parseStrict",(uno.Any('com.sun.star.util.URL',url),))
        return x[0]==True and x[1] or Null        
        
    def getPropertyValue(self, n, v):
        p = uno.createUnoStruct('com.sun.star.beans.PropertyValue')
        p.Name = n
        p.Value = v
        return p

    def setMsgboxWindow(self, win):
        self.win = win

    def msgbox(self,title='<Dummy>',msg='<Hello World>',etyp=MESSAGEBOX,ebtn=BUTTONS_OK):
        mbox = self.tk.createMessageBox(self.win,etyp,ebtn,title,msg)
        return mbox.execute()        
    
    def mri(self, obj):
        mri = self.createUnoService("mytools.Mri")
        mri.inspect(obj)
It provides a Desktop, a message box, Mri, createUnoService, PropertyValues and URL structs.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Bastien
Posts: 61
Joined: Mon May 12, 2014 2:45 pm

Re: APSO No module named 'apso_utils'

Post by Bastien »

I added the path to ~/.profile and (not so) miracously, it worked!
IMHO, this is a detail that deserves to be added at the installation notes in https://extensions.libreoffice.org/exte ... for-python.
Thanks a lot !
LibreOffice 6.2.3.2 on Ubuntu 19.04
hubert lambert
Posts: 145
Joined: Mon Jun 13, 2016 10:50 am

Re: [Solved] APSO No module named 'apso_utils'

Post by hubert lambert »

Hi,

As said in the Apso readme file:
Apso readme wrote:APSO comes with a small library apso_utils that contains some helpers for debugging purpose during macro writing. [...] The module apso_utils can't be imported before APSO was first loaded. Only the console macro is accessible outside APSO.
If you don't launch Apso once in your session, apso_utils will not be found ;) .
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
Bastien
Posts: 61
Joined: Mon May 12, 2014 2:45 pm

Re: [Solved] APSO No module named 'apso_utils'

Post by Bastien »

I'm sorry but I don't know what does mean
The module apso_utils can't be imported before APSO was first loaded.

How do you load a module? It seems quite different than expanding the PYTHONPATH.
Last edited by Bastien on Thu Mar 07, 2019 4:25 pm, edited 1 time in total.
LibreOffice 6.2.3.2 on Ubuntu 19.04
hubert lambert
Posts: 145
Joined: Mon Jun 13, 2016 10:50 am

Re: [Solved] APSO No module named 'apso_utils'

Post by hubert lambert »

It means:
hubert lambert wrote:If you don't launch Apso once in your session, apso_utils will not be found.
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
Bastien
Posts: 61
Joined: Mon May 12, 2014 2:45 pm

Re: [Solved] APSO No module named 'apso_utils'

Post by Bastien »

And how do you launch it? Calling MsgBox(), Mri() from the macro menu? It would be a non sense. I keep thinking expanding the path is much more usefull information.
LibreOffice 6.2.3.2 on Ubuntu 19.04
hubert lambert
Posts: 145
Joined: Mon Jun 13, 2016 10:50 am

Re: [Solved] APSO No module named 'apso_utils'

Post by hubert lambert »

You launch Apso from Tools -> Macros -> Organize python scripts or with the shortcut Alt+Shift+F11.
What I mean is that Apso helper functions are only designed to be used while writing macro (i.e. while Apso is opened), as debugging tools.
If you want to use these helpers as everyday functions, then yes, expand the python path in your script or, better, create your own tool library in the user pythonpath subfolder (example in Villeroy's post).
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
Bastien
Posts: 61
Joined: Mon May 12, 2014 2:45 pm

Re: [Solved] APSO No module named 'apso_utils'

Post by Bastien »

Thanks for all that enlightment! I now understand better the way it should be used.
LibreOffice 6.2.3.2 on Ubuntu 19.04
hubert lambert
Posts: 145
Joined: Mon Jun 13, 2016 10:50 am

Re: [Solved] APSO No module named 'apso_utils'

Post by hubert lambert »

Maybe a better way to load apso_utils without launching Apso or modifying the syspath would be to instanciate Apso somewhere in the code before the import statement:

Code: Select all

def entryfunc(event=None):
    ctx = XSCRIPTCONTEXT.getComponentContext()
    ctx.ServiceManager.createInstance("apso.python.script.organizer.impl")
    # now we can use apso_utils library
    from apso_utils import console
    console() 
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
Post Reply