ntp.util: Fix rpeers mode in PeerSummary.summary
[ntpsec.git] / README-PYTHON
blobbc7e1b7417c5c5a02c627fe2be27fd9cd9b9a2ea
1 If you are trying to debug something like:
2   ImportError: No module named ntp
3 you have come to the right place.
5 The default location where we install our python libraries is
6   /usr/local/lib/pythonX.Y/site-packages/
7 where X and Y are the python version numbers.
9 Unfortunately, that's not on the default search path of several
10 OSes/distros, in particular Fedora and NetBSD.
11 (Fixed in Fedora 39, Sep-2023, ??)
13 Python has a search path that is used to find library modules when
14 you import them.  You can see your search path with:
15   python2 -c "import sys; print sys.path"
17   python3 -c "import sys; print(sys.path)"
19 Info on Python's search path:
20   https://docs.python.org/2/tutorial/modules.html
22   https://docs.python.org/3/tutorial/modules.html
26 There are several ways to make things work.
28 1: You can modify the location where waf will install the libraries.
29 For NetBSD, something like this should work:
30   ./waf configure \
31     --pythondir=/usr/pkg/lib/python2.7/site-packages \
32     --pythonarchdir=/usr/pkg/lib/python2.7/site-packages \
33     ...
34 You need to specify it at configure time.  Install time is too late.
37 2: You can setup your PYTHONPATH with something like this:
38   export PYTHONPATH=/usr/local/lib/python2.7/site-packages
39 For bash, you can add that line to your .bashrc or the system /etc/bashrc
40 If you don't put it in the system file, all users will have to do this,
41 including root if root uses any ntp scripts.
44 3: You can add to the default search path by setting up a .pth file
45 with something like this:
46   echo /usr/local/lib64/python3.11/site-packages > \
47     /usr/lib/python3.11/site-packages/ntpsec.pth
48 This works for all users, including root.
49 Note that the pth file must be on the default Python search path.
52 OTOH if you run into something like:
53     Traceback (most recent call last):
54       File "/usr/bin/ntpdig", line 419, in <module>
55         timeout=timeout)
56       File "/usr/bin/ntpdig", line 109, in queryhost
57         keyid, keytype, passwd)
58       File "/usr/lib/python3/dist-packages/ntp/packet.py", line 1747, in compute_mac
59         if not ntp.ntpc.checkname(keytype):
60     AttributeError: module 'ntp.ntpc' has no attribute 'checkname'
62 Then you probably want to either uninstall the previous Python extension, or
63 install one after 1.1.9 (798b93) by adding the '--enable-pylib ext' option
64 without quotes.
66 OTOH if you are running into something like:
67     Traceback (most recent call last):
68     File "/usr/bin/ntpdig", line 19, in <module>
69         import ntp.packet
70     File "/usr/lib/python3/dist-packages/ntp/packet.py", line 219, in <module>
71         import ntp.ntpc
72     File "/usr/lib/python3/dist-packages/ntp/ntpc.py", line 52, in <module>
73         _ntpc = _importado()
74     File "/usr/lib/python3/dist-packages/ntp/ntpc.py", line 38, in _importado
75         return _dlo(ntpc_paths)
76     File "/usr/lib/python3/dist-packages/ntp/ntpc.py", line 49, in _dlo
77         raise OSError("Can't find %s library" % LIB)
78     OSError: Can't find ntpc library
80 That means that ntpc.py looked for libnptc.so in the usual places and could
81 not find it.  If it is being installed to the wrong location on your platform,
82 you can correct the install location using: waf configure --libdir=  If you
83 are intentionally installing to a non-default location, you can modify the
84 dynamic linker's search path globally (e.g. /etc/ld.so.conf or
85 /etc/ld.so.conf.d/) or in your environment (e.g. LD_LIBRARY_PATH).
87 On some platforms, it is necessary to run ldconfig after installing libraries.
88 This is normally done by the waf install step, but it may have failed.  When
89 using a temporary --destdir (e.g. as part of package builds), ldconfig must be
90 run manually after the library is installed to its final location.