← Back to Index

Voikko
Using in Python applications

The Python interface for Libvoikko is available from the Python Package Index:

    pip3 install libvoikko

Additionally you need to have the native libvoikko library and at least one dictionary installed in order to use it.

To get started with using the library you can look at the built in documentation:

    from libvoikko import Voikko
    help(Voikko)

Installing the native library

... or how to resolve OSError: libvoikko.so.1: cannot open shared object file: No such file or directory

... or FileNotFoundError: Could not find module 'libvoikko-1.dll'. Try using the full path with constructor syntax.

Note that the error message may vary slightly between different operating systems. You need to have the native libvoikko library available in a place where the OS specific library loading mechanism will find it.

It is also possible to load the native library from custom path. To do this call static method Voikko.setLibrarySearchPath(path) before constructing a new Voikko instance.

Versions of the Python package and the native library do not need to be exactly the same. Generally your native library should have the same or higher version that the Python package.

Installing suitable dictionary files

... or how to resolve libvoikko.VoikkoException: Initialization of Voikko failed: No valid dictionaries were found

You need to have a dictionary installed that is compatible with your version of libvoikko and matches the language (and language variant) you specified as a parameter in the constructor for Voikko object. Here you can download various dictionary packages for Finnish. The dictionary packages need to be unzipped but the directory structure within the packages must be preserved.

On Linux and macOS you can unpack the dictionaries under /etc/voikko or $HOME/.voikko. On Windows, when using libvoikko-1.dll linked above, the files can be unpacked under C:\Voikko. Another, more portable option is to choose an application specific installation directory for the dictionaries and use the optional path constructor parameter for Voikko to specify that directory.