Importing in Python extensions

Discussions about using 3rd party extension with OpenOffice.org
Post Reply
MisterMillennia
Posts: 3
Joined: Sun Aug 30, 2015 12:31 pm

Importing in Python extensions

Post by MisterMillennia »

Hello everyone, once again I have benign problems that should be relatively simple to figure out, but have me stumped:

I have a simple Hello World python function, and I want to give it more functionality by importing classes from another python file in the same folder. In normal python programming this would be as simple as writing

Code: Select all

import ClassFile
But after compilation of the files into an extension, I get an ImportError stating that it cannot find ClassFile. What do I need to do to get this python file to import into the Hello World function?

An extension on that question; I am also trying to use nltk (an external, 3rd party library for python), which would be imported in the same way, but is not contained within the extension file, it is instead installed in python/Lib/site-packages/nltk. Do I need to install this library into the OpenOffice python distribution, or is it more complicated to get third-party libraries working with OpenOffice?
OpenOffice 4.1.1 on Windows 8
User avatar
karolus
Volunteer
Posts: 1159
Joined: Sat Jul 02, 2011 9:47 am

Re: Importing in Python extensions

Post by karolus »

OpenOffice has made some Extra-rule for import Search-Path's, your importable Module should stored into a Folder `pythonpath` below `.../Scripts/python/` inside.. [yourExtensionPackage | your $user-config ]

@nltk: It seems the package is written in pure python ? - if so - try to copy or link nltk into your ...openoffice4/program/python-core-2.7.6/lib/site-packages/-folder
AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 7.6 flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
mauriciobaeza
Posts: 56
Joined: Thu Apr 22, 2010 5:03 am

Re: Importing in Python extensions

Post by mauriciobaeza »

Is easy... look...

Code: Select all

┌─[mau][mau]->{~/.openoffice/4/user/Scripts}
└──> tree 
.
`-- python
    |-- mymacros.py
    `-- pythonpath
        `-- util.py
util.py

Code: Select all

import datetime

def now():
    return datetime.datetime.now()
and mymacros.py

Code: Select all

import uno
import util


def test():
    print (util.now())
    return
result

Code: Select all

┌─[mau][mau]->{~}
└──> aoo
2015-11-12 21:31:15.961675
Best regards
______________________________________________
Everything not given is lost
AOO 4.1 / LibO 4.3 on ArchLinux with Gnome3
Please, I do not answer private questions, you use the forum
Post Reply