Page 1 of 1

Importing in Python extensions

Posted: Fri Sep 04, 2015 3:20 am
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?

Re: Importing in Python extensions

Posted: Fri Sep 04, 2015 5:28 am
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

Re: Importing in Python extensions

Posted: Fri Nov 13, 2015 5:35 am
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