Importing in Python extensions

Discussions about using 3rd party extension with

Importing in Python extensions

Postby MisterMillennia » Fri Sep 04, 2015 3:20 am

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   Expand viewCollapse view
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
Posts: 3
Joined: Sun Aug 30, 2015 12:31 pm

Re: Importing in Python extensions

Postby karolus » Fri Sep 04, 2015 5:28 am

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 - 5.1 … on Linux Mint17
User avatar
Posts: 852
Joined: Sat Jul 02, 2011 9:47 am

Re: Importing in Python extensions

Postby mauriciobaeza » Fri Nov 13, 2015 5:35 am

Is easy... look...
Code: Select all   Expand viewCollapse view
└──> tree
`-- python
    `-- pythonpath
Code: Select all   Expand viewCollapse view
import datetime

def now():

Code: Select all   Expand viewCollapse view
import uno
import util

def test():
    print (

Code: Select all   Expand viewCollapse view
└──> 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
Posts: 56
Joined: Thu Apr 22, 2010 5:03 am

Return to Extensions

Who is online

Users browsing this forum: No registered users and 0 guests