[Solved] APSO No module named 'apso_utils'

Discussions about using 3rd party extension with OpenOffice.org

[Solved] APSO No module named 'apso_utils'

Postby Bastien » Wed Mar 06, 2019 5:08 pm

Just installed ASPO extension. I thought I could then use a normal import from my python macro as following:
Code: Select all   Expand viewCollapse view
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.1.1.2 on Ubuntu 18.04
Bastien
 
Posts: 42
Joined: Mon May 12, 2014 2:45 pm

Re: APSO No module named 'apso_utils'

Postby Villeroy » Wed Mar 06, 2019 5:40 pm

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, OpenOffice 4.x & LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26627
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: APSO No module named 'apso_utils'

Postby Bastien » Wed Mar 06, 2019 6:06 pm

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.1.1.2 on Ubuntu 18.04
Bastien
 
Posts: 42
Joined: Mon May 12, 2014 2:45 pm

Re: APSO No module named 'apso_utils'

Postby RoryOF » Wed Mar 06, 2019 6:12 pm

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.6 on Xubuntu 18.04.2 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 28748
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: APSO No module named 'apso_utils'

Postby Bastien » Wed Mar 06, 2019 6:44 pm

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.1.1.2 on Ubuntu 18.04
Bastien
 
Posts: 42
Joined: Mon May 12, 2014 2:45 pm

Re: APSO No module named 'apso_utils'

Postby Villeroy » Wed Mar 06, 2019 7:00 pm

You may try a link
Code: Select all   Expand viewCollapse view
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   Expand viewCollapse view
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, OpenOffice 4.x & LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26627
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: APSO No module named 'apso_utils'

Postby Bastien » Thu Mar 07, 2019 3:45 pm

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/extensions/apso-alternative-script-organizer-for-python.
Thanks a lot !
LibreOffice 6.1.1.2 on Ubuntu 18.04
Bastien
 
Posts: 42
Joined: Mon May 12, 2014 2:45 pm

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

Postby hubert lambert » Thu Mar 07, 2019 3:51 pm

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
hubert lambert
 
Posts: 123
Joined: Mon Jun 13, 2016 10:50 am

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

Postby Bastien » Thu Mar 07, 2019 4:24 pm

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.1.1.2 on Ubuntu 18.04
Bastien
 
Posts: 42
Joined: Mon May 12, 2014 2:45 pm

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

Postby hubert lambert » Thu Mar 07, 2019 4:25 pm

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
hubert lambert
 
Posts: 123
Joined: Mon Jun 13, 2016 10:50 am

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

Postby Bastien » Thu Mar 07, 2019 4:41 pm

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.1.1.2 on Ubuntu 18.04
Bastien
 
Posts: 42
Joined: Mon May 12, 2014 2:45 pm

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

Postby hubert lambert » Thu Mar 07, 2019 4:51 pm

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
hubert lambert
 
Posts: 123
Joined: Mon Jun 13, 2016 10:50 am

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

Postby Bastien » Thu Mar 07, 2019 4:57 pm

Thanks for all that enlightment! I now understand better the way it should be used.
LibreOffice 6.1.1.2 on Ubuntu 18.04
Bastien
 
Posts: 42
Joined: Mon May 12, 2014 2:45 pm

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

Postby hubert lambert » Sun Mar 10, 2019 1:43 pm

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   Expand viewCollapse view
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
hubert lambert
 
Posts: 123
Joined: Mon Jun 13, 2016 10:50 am


Return to Extensions

Who is online

Users browsing this forum: No registered users and 1 guest