-
Notifications
You must be signed in to change notification settings - Fork 0
/
python.html
63 lines (49 loc) · 3.82 KB
/
python.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Voikko – Using in Python applications</title>
<link rel="stylesheet" type="text/css" href="stylesheets/styles.css" />
</head>
<body>
<p class="linkback"><a href=".">← Back to Index</a></p>
<h1>Voikko<br /><small>Using in Python applications</small></h1>
<p>The Python interface for Libvoikko is available from the <a href="https://pypi.org/">Python Package Index</a>:</p>
<pre>
pip3 install libvoikko
</pre>
<p>Additionally you need to have the native libvoikko library and at least one dictionary installed in order to use it.</p>
<p>To get started with using the library you can look at the built in documentation:</p>
<pre>
from libvoikko import Voikko
help(Voikko)
</pre>
<h2>Installing the native library</h2>
<p style="font-size:85%; text-align:right">... or how to resolve <kbd>OSError: libvoikko.so.1: cannot open shared object file: No such file or directory</kbd></p>
<p style="font-size:85%; text-align:right">... or <kbd>FileNotFoundError: Could not find module 'libvoikko-1.dll'. Try using the full path with constructor syntax.</kbd></p>
<p>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.</p>
<ul>
<li>Most modern <em>Linux</em> distributions contain the <kbd>libvoikko</kbd> package; installing that should be sufficient.</li>
<li>On <em>Windows</em> you should <em>note that Python 3.8 changed the way how native libraries are loaded</em>.
<a href="https://www.puimula.org/htp/testing/voikko-sdk/win-crossbuild/">Download the library for Windows</a> (choose 32 or 64 bit version according to your Python interpreter version)
and place <kbd>libvoikko-1.dll</kbd> in some directory such as <kbd>c:\Voikko</kbd>. Then, immediately after importing the library call <kbd>Voikko.setLibrarySearchPath("c:/Voikko")</kbd>
to ensure that the library will be correctly loaded.</li>
<li>On <em>macOS</em> Homebrew ships libvoikko and Finnish dictionary in one package: <kbd>brew install libvoikko</kbd>.</li>
</ul>
<p>It is also possible to load the native library from custom path. To do this call static method <kbd>Voikko.setLibrarySearchPath(path)</kbd> before constructing
a new Voikko instance.</p>
<p>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.</p>
<h2>Installing suitable dictionary files</h2>
<p style="font-size:85%; text-align:right">... or how to resolve <kbd>libvoikko.VoikkoException: Initialization of Voikko failed: No valid dictionaries were found</kbd></p>
<p>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. <a href="https://www.puimula.org/htp/testing/voikko-snapshot-v5/">Here you can download various dictionary packages
for Finnish</a>. The dictionary packages need to be unzipped but the directory structure within the packages must be preserved.</p>
<p>On Linux and macOS you can unpack the dictionaries under <kbd>/etc/voikko</kbd> or <kbd>$HOME/.voikko</kbd>. On Windows, when using libvoikko-1.dll linked above,
the files can be unpacked under <kbd>C:\Voikko</kbd>. Another, more portable option is to choose an application specific installation directory for the dictionaries and use the optional <kbd>path</kbd>
constructor parameter for Voikko to specify that directory.</p>
<div style="clear:both;" />
</body>
</html>