building python package

144 views
Skip to first unread message

lipp f

unread,
Oct 25, 2023, 9:35:52 PM10/25/23
to Ledger
Wondering if I can get a bit of help. TIA.

This is what I've done 

- download and unpack the release
- in the release folder, run 
$ ./acprep update  --prefix=/usr/local -- -DUSE_PYTHON=ON

and this is what I'm getting:

/home/<user>/sc_invest/ledger-3.2.1/./acprep:195: DeprecationWarning: inspect.getargspec() is deprecated since Python 3.0, use inspect.signature() or inspect.getfullargspec()
  argspec = inspect.getargspec(self.main)
acprep: INFO: Invoking primary phase: update
acprep: INFO: Executing phase: update
acprep: INFO: Executing phase: pull
acprep: INFO: Executing phase: make
acprep: INFO: Executing phase: config
acprep: INFO: Executing phase: configure
acprep: INFO: System type is => b'Linux'
acprep: INFO: Setting up build flavor => debug
CMake Warning:
  No source or binary directory provided.  Both will be assumed to be the
  same as the current working directory, but note that this warning will
  become a fatal error in future CMake releases.


-- Found Python: /home/<user>/miniconda3/envs/invest_01/bin/python3.9 (found version "3.9.16") found components: Interpreter
-- Found Python: /home/<user>/miniconda3/envs/invest_01/bin/python3.9 (found version "3.9.16") found components: Interpreter Development
CMake Error at /usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake:117 (find_package):
  Found package configuration file:

    /usr/lib/x86_64-linux-gnu/cmake/boost_python-1.71.0/boost_python-config.cmake

  but it set boost_python_FOUND to FALSE so package "boost_python" is
  considered to be NOT FOUND.  Reason given by package:

  No suitable build variant has been found.

  The following variants have been tried and rejected:

  * libboost_python38.so.1.71.0 (3.8, Boost_PYTHON_VERSION=3.9)

  * libboost_python38.a (3.8, Boost_PYTHON_VERSION=3.9)

Call Stack (most recent call first):
  /usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake:182 (boost_find_component)
  /usr/share/cmake-3.16/Modules/FindBoost.cmake:443 (find_package)
  CMakeLists.txt:82 (find_package)


-- Configuring incomplete, errors occurred!
See also "/home/<user>/sc_invest/ledger-3.2.1/CMakeFiles/CMakeOutput.log".
acprep: ERROR: Execution failed: cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_DEBUG=1 -DUSE_PYTHON=ON

lipp f

unread,
Dec 14, 2023, 3:33:03 PM12/14/23
to Ledger
anyone? really need to get this working.  thanks.

Alexis

unread,
Dec 14, 2023, 4:10:41 PM12/14/23
to ledge...@googlegroups.com
Hi,

It seems that in the environment in which you are trying to build
ledger has Python version 3.9 installed (maybe a venv?), but
the Boost library (version 1.71) provides bindings for Python 3.8.

Did you run `./acprep dependencies`?
What Linux distro and version are you on?
Are you running a venv (or something similar)?


Cheers
Alexis

lipp f

unread,
Dec 14, 2023, 4:20:24 PM12/14/23
to Ledger
I've  done this:
$ conda create -n ldg-build python=3.8 boost py-boost zlib

$ ./acprep dependencies
.......
0 upgraded, 0 newly installed, 0 to remove and 132 not upgraded.

$ cmake -Bbuild -S. -DUSE_PYTHON:BOOL=ON^C
-- Found Python: /home/sergiu/miniconda3/envs/invest_01/bin/python3.9 (found version "3.9.16") found components: Interpreter
-- Found Python: /home/sergiu/miniconda3/envs/invest_01/bin/python3.9 (found version "3.9.16") found components: Interpreter Development

CMake Error at /usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake:117 (find_package):
  Found package configuration file:

    /usr/lib/x86_64-linux-gnu/cmake/boost_python-1.71.0/boost_python-config.cmake

  but it set boost_python_FOUND to FALSE so package "boost_python" is
  considered to be NOT FOUND.  Reason given by package:

  No suitable build variant has been found.

  The following variants have been tried and rejected:

  * libboost_python38.so.1.71.0 (3.8, Boost_PYTHON_VERSION=3.9)

  * libboost_python38.a (3.8, Boost_PYTHON_VERSION=3.9)

Call Stack (most recent call first):
  /usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake:182 (boost_find_component)
  /usr/share/cmake-3.16/Modules/FindBoost.cmake:443 (find_package)
  CMakeLists.txt:92 (find_package)



-- Configuring incomplete, errors occurred!

lipp f

unread,
Dec 14, 2023, 4:22:04 PM12/14/23
to Ledger
$ python -V
Python 3.8.18

lipp f

unread,
Dec 14, 2023, 4:25:15 PM12/14/23
to Ledger
$ cat /etc/issue
Ubuntu 20.04.6 LTS \n \l

Alexis

unread,
Dec 14, 2023, 5:12:01 PM12/14/23
to ledge...@googlegroups.com
Hi,

CMake is quite explicit about which python it has found:

-- Found Python: /home/sergiu/miniconda3/envs/invest_01/bin/python3.9

This does not match with the 3.8 that is in your environment.

In order to build Ledger Python correctly the Python found by CMake
must match the Python that boost was compiled with (typically system
Python). I'd try to avoid using venv or conda and stick with the system
Python.

I've been working on and off on adding support to make Ledger
installable via pip (see https://github.com/ledger/ledger/pull/2246)
but it may be a while until that is finished completely.


Hope this helps :)

lipp f

unread,
Dec 16, 2023, 9:46:12 PM12/16/23
to Ledger
If you look two messages back, you can actually see that default python is 3.8.18. 
I'm wondering if you can troubleshoot why CMake does not use the default python, but another one (3.9), and how it founds that one. Some recommendations to change this behaviour, maybe?
TIA.

Alexis

unread,
Dec 17, 2023, 2:11:17 PM12/17/23
to ledge...@googlegroups.com
Hi

from the information presented I have no clear understanding of the
environment and setup and I'm unfamiliar with conda and its specialities.

It seems to me as if some environment manager (miniconda?) is
setting up the environment so its Python (version 3.9) is preferred.
Is there a way, where you could have a shell that only uses the system
Python and retry building ledger with Python support?

Unfortunately I have no good advice for troubleshooting CMake
apart from reading FindPython.cmake¹ :/

What I suggest is giving CMake a hint about which Python you'd prefer to
be used (see Python_ROOT_DIR in FindPython module documentation²).

If I'm not mistaken on Ubuntu the Python root installation directory
should be /usr as the python executable resides in /usr/bin/python
and its libraries in /usr/lib/python3.8; at least according the
file Ubunut filelist³

How about trying the following:
% rm -rf ./build
% ./acprep configure --python -- -DPython_ROOT_DIR=/usr
% ./acprep make
% /usr/bin/env PYTHONPATH=$PWD/build/ledger/debug python3 -c 'import ledger; dir(ledger)'

or if your prefer to avoid using acprep:
% rm -rf ./build
% cmake --fresh -Bbuild -S. -DUSE_PYTHON:BOOL=ON -DPython_ROOT_DIR=/usr
% make -j8 -Cbuild
% /usr/bin/env PYTHONPATH=$PWD/build python3 -c 'import ledger; dir(ledger)'


Hope this helps!
If it's not too much to ask I'd appreciate to hear back if you run
into issues and if you succeed I'd be interested in what you think
would have helped you and made building Ledger Python easier for you.


Best
Alexis

¹ https://github.com/Kitware/CMake/blob/master/Modules/FindPython.cmake
² https://cmake.org/cmake/help/latest/module/FindPython.html#hints
³ https://packages.ubuntu.com/focal/amd64/libpython3.8-minimal/filelist

lipp f

unread,
Dec 19, 2023, 10:06:06 AM12/19/23
to Ledger
Based on your suggestions I made some progress. It finds boost in configure and fails with  "fatal error: boost/filesystem/directory.hpp: No such file or directory" in make.

The file exists in /home/sergiu/miniconda3/envs/ldg-build/include/boost/filesystem/directory.hpp but it is not being picked up. Is there an option to add something to make INCLUDE?

$ rm -rf ./build
$ ./acprep configure --python -- -DPython_ROOT_DIR=/home/sergiu/miniconda3/envs/ldg-build/
acprep: INFO: Invoking primary phase: configure

acprep: INFO: Executing phase: configure
acprep: INFO: System type is => Linux

acprep: INFO: Setting up build flavor => debug
CMake Warning:
  No source or binary directory provided.  Both will be assumed to be the
  same as the current working directory, but note that this warning will
  become a fatal error in future CMake releases.


-- Found Python: /home/sergiu/miniconda3/envs/ldg-build/bin/python3.8 (found version "3.8.18") found components: Interpreter
-- Found Python: /home/sergiu/miniconda3/envs/ldg-build/bin/python3.8 (found version "3.8.18") found components: Interpreter Development
-- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake (found suitable version "1.71.0", minimum required is "1.49.0") found components: date_time filesystem system iostreams regex unit_test_framework python38 missing components: nowide
-- Looking for getpwuid
-- Looking for getpwuid - found
-- Looking for getpwnam
-- Looking for getpwnam - found
-- Looking for ioctl
-- Looking for ioctl - found
-- Looking for isatty
-- Looking for isatty - found
-- Performing Test UNIX_PIPES_COMPILES
-- Performing Test UNIX_PIPES_COMPILES - Success
-- Performing Test BOOST_REGEX_UNICODE_RUNS
-- Performing Test BOOST_REGEX_UNICODE_RUNS - Success
-- Performing Test BOOST_MAKE_SETTER_COMPILES
-- Performing Test BOOST_MAKE_SETTER_COMPILES - Success
-- Looking for readline in edit
-- Looking for readline in edit - found
-- Performing Test HAVE_WORKING_UTFCPP
-- Performing Test HAVE_WORKING_UTFCPP - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /home/sergiu/ledger-3.3.2
$  ./acprep make
acprep: INFO: Invoking primary phase: make

acprep: INFO: Executing phase: make
acprep: INFO: Executing phase: config
acprep: INFO: Executing phase: configure
acprep: INFO: System type is => Linux

acprep: INFO: Setting up build flavor => debug
Scanning dependencies of target libledger
[  1%] Building CXX object src/CMakeFiles/libledger.dir/cmake_pch.hxx.gch
In file included from /home/sergiu/ledger-3.3.2/src/CMakeFiles/libledger.dir/cmake_pch.hxx:5,
                 from <command-line>:
/home/sergiu/ledger-3.3.2/system.hh:151:10: fatal error: boost/filesystem/directory.hpp: No such file or directory
  151 | #include <boost/filesystem/directory.hpp>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [src/CMakeFiles/libledger.dir/build.make:64: src/CMakeFiles/libledger.dir/cmake_pch.hxx.gch] Error 1
make[1]: *** [CMakeFiles/Makefile2:250: src/CMakeFiles/libledger.dir/all] Error 2
make: *** [Makefile:163: all] Error 2
acprep: ERROR: Execution failed: make

Alexis

unread,
Dec 19, 2023, 10:26:03 AM12/19/23
to ledge...@googlegroups.com
Hi,

> Based on your suggestions I made some progress. It finds boost in configure

That's great to hear!

> but it is not being picked up. Is there an option to add something to make
> INCLUDE?

There sure is: CMake's FindBoost Module¹ also offers hints with which
an installation prefix or the preferred include and library directory
can be set (for details see the FindBoost documentation²).
Does specifying -DBOOST_ROOT help?

% ./acprep configure --python -- \
-DPython_ROOT_DIR=/home/sergiu/miniconda3/envs/ldg-build/ \
-DBOOST_ROOT=/home/sergiu/miniconda3/envs/ldg-build/ \
-DBoost_NO_SYSTEM_PATHS:BOOL=ON

The last hint "disable[s] searching in locations not specified by these
hint variables"; configuring ledger using CMake may work without it.


Godspeed :)


¹ https://github.com/Kitware/CMake/blob/master/Modules/FindBoost.cmake
² https://cmake.org/cmake/help/latest/module/FindBoost.html#hints

lipp f

unread,
Dec 19, 2023, 11:20:51 AM12/19/23
to Ledger
More progress:
- first I have to do ./acprep clean with each attempt
- before I've seen your last message, i did ./acprep configure --prefix=/usr/local -- -DUSE_PYTHON=ON -DPython_ROOT_DIR=/home/sergiu/miniconda3/envs/ldg-build/
- I also tryed your options
- in make, both sets of options compile to the end with some warnings but no errors, and both of them fail in linking with 6 "undefined reference to  NCURSES6_TINFO symbols in libedit.so:

[ 83%] Building CXX object src/CMakeFiles/ledger.dir/global.cc.o
In file included from /home/sergiu/miniconda3/envs/ldg-build/include/boost/function/detail/requires_cxx11.hpp:9,
                 from /home/sergiu/miniconda3/envs/ldg-build/include/boost/function/detail/prologue.hpp:12,
                 from /home/sergiu/miniconda3/envs/ldg-build/include/boost/function.hpp:30,
                 from /home/sergiu/miniconda3/envs/ldg-build/include/boost/algorithm/string/detail/find_iterator.hpp:18,
                 from /home/sergiu/miniconda3/envs/ldg-build/include/boost/algorithm/string/find_iterator.hpp:24,
                 from /home/sergiu/miniconda3/envs/ldg-build/include/boost/algorithm/string/iter_find.hpp:27,
                 from /home/sergiu/miniconda3/envs/ldg-build/include/boost/algorithm/string/split.hpp:16,
                 from /home/sergiu/miniconda3/envs/ldg-build/include/boost/algorithm/string.hpp:23,
                 from /home/sergiu/ledger-3.3.2/system.hh:137,
                 from /home/sergiu/ledger-3.3.2/src/global.cc:32:
/home/sergiu/miniconda3/envs/ldg-build/include/boost/bind.hpp:36:1: note: #pragma message: The practice of declaring the Bind placeholders (_1, _2, ...) in the global namespace is deprecated. Please use <boost/bind/bind.hpp> + using namespace boost::placeholders, or define BOOST_BIND_GLOBAL_PLACEHOLDERS to retain the current behavior.
   36 | BOOST_PRAGMA_MESSAGE(
      | ^~~~~~~~~~~~~~~~~~~~
[ 85%] Linking CXX executable ../ledger
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libedit.so: undefined reference to `tgoto@NCURSES6_TINFO_5.0.19991023'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libedit.so: undefined reference to `tgetent@NCURSES6_TINFO_5.0.19991023'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libedit.so: undefined reference to `tgetnum@NCURSES6_TINFO_5.0.19991023'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libedit.so: undefined reference to `tputs@NCURSES6_TINFO_5.0.19991023'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libedit.so: undefined reference to `tgetflag@NCURSES6_TINFO_5.0.19991023'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libedit.so: undefined reference to `tgetstr@NCURSES6_TINFO_5.0.19991023'
collect2: error: ld returned 1 exit status
make[2]: *** [src/CMakeFiles/ledger.dir/build.make:111: ledger] Error 1
make[1]: *** [CMakeFiles/Makefile2:223: src/CMakeFiles/ledger.dir/all] Error 2

make: *** [Makefile:163: all] Error 2
acprep: ERROR: Execution failed: make


This is referred libedit.so :
$ ls -l /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libedit.so
lrwxrwxrwx 1 root root 17 Jan  3  2020 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libedit.so -> libedit.so.2.0.63
and here are the 6 symbols:
$ readelf -Ws  /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libedit.so  | grep -E 'tgoto|tgetent|tgetnum|tputs|tgetflag|tgetstr'
     7: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND tputs@NCURSES6_TINFO_5.0.19991023 (4)
    31: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND tgoto@NCURSES6_TINFO_5.0.19991023 (4)
    84: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND tgetnum@NCURSES6_TINFO_5.0.19991023 (4)
    90: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND tgetflag@NCURSES6_TINFO_5.0.19991023 (4)
    91: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND tgetstr@NCURSES6_TINFO_5.0.19991023 (4)
   123: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND tgetent@NCURSES6_TINFO_5.0.19991023 (4)

lipp f

unread,
Dec 19, 2023, 12:58:40 PM12/19/23
to Ledger
I am getting close. I had to uninstall two python packages. readline and ncurses. Compiling and linking ends without errors.
I can run $ ./ledger --version and I'm getting "Ledger 3.3.2-20230330", which is great, but the python test, fails on "import ledger".

$ make test
100% tests passed, 0 tests failed out of 411

Total Test time (real) =  26.18 sec

I did the build with ./acprep configure --prefix=~/local/bin ... . When i run make install, I was expecting everything to go under $HOME/local/bin but it goes under /usr/local and destroys my previously installed ubuntu package. Also, there is no trace of the python module under /home/sergiu/miniconda3/envs/ldg-build/lib/python3.8/site-packages. 

$ sudo make install
[sudo] password for sergiu:
[ 80%] Built target libledger
[ 85%] Built target ledger
[ 95%] Built target MathTests
[100%] Built target UtilTests
Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/lib/libledger.so.3
-- Set runtime path of "/usr/local/lib/libledger.so.3" to "/usr/local/lib"
-- Up-to-date: /usr/local/lib/libledger.so
-- Up-to-date: /usr/local/include/ledger/account.h
-- Up-to-date: /usr/local/include/ledger/amount.h
-- Up-to-date: /usr/local/include/ledger/annotate.h
-- Up-to-date: /usr/local/include/ledger/balance.h
-- Up-to-date: /usr/local/include/ledger/chain.h
-- Up-to-date: /usr/local/include/ledger/commodity.h
-- Up-to-date: /usr/local/include/ledger/compare.h
-- Up-to-date: /usr/local/include/ledger/context.h
-- Up-to-date: /usr/local/include/ledger/convert.h
-- Up-to-date: /usr/local/include/ledger/csv.h
-- Up-to-date: /usr/local/include/ledger/draft.h
-- Up-to-date: /usr/local/include/ledger/emacs.h
-- Up-to-date: /usr/local/include/ledger/error.h
-- Up-to-date: /usr/local/include/ledger/expr.h
-- Up-to-date: /usr/local/include/ledger/exprbase.h
-- Up-to-date: /usr/local/include/ledger/filters.h
-- Up-to-date: /usr/local/include/ledger/flags.h
-- Up-to-date: /usr/local/include/ledger/format.h
-- Up-to-date: /usr/local/include/ledger/generate.h
-- Up-to-date: /usr/local/include/ledger/global.h
-- Up-to-date: /usr/local/include/ledger/gpgme.h
-- Up-to-date: /usr/local/include/ledger/history.h
-- Up-to-date: /usr/local/include/ledger/item.h
-- Up-to-date: /usr/local/include/ledger/iterators.h
-- Up-to-date: /usr/local/include/ledger/journal.h
-- Up-to-date: /usr/local/include/ledger/lookup.h
-- Up-to-date: /usr/local/include/ledger/mask.h
-- Up-to-date: /usr/local/include/ledger/op.h
-- Up-to-date: /usr/local/include/ledger/option.h
-- Up-to-date: /usr/local/include/ledger/output.h
-- Up-to-date: /usr/local/include/ledger/parser.h
-- Up-to-date: /usr/local/include/ledger/pool.h
-- Up-to-date: /usr/local/include/ledger/post.h
-- Up-to-date: /usr/local/include/ledger/precmd.h
-- Up-to-date: /usr/local/include/ledger/predicate.h
-- Up-to-date: /usr/local/include/ledger/print.h
-- Up-to-date: /usr/local/include/ledger/pstream.h
-- Up-to-date: /usr/local/include/ledger/ptree.h
-- Up-to-date: /usr/local/include/ledger/pyinterp.h
-- Up-to-date: /usr/local/include/ledger/pyutils.h
-- Up-to-date: /usr/local/include/ledger/query.h
-- Up-to-date: /usr/local/include/ledger/quotes.h
-- Up-to-date: /usr/local/include/ledger/report.h
-- Up-to-date: /usr/local/include/ledger/scope.h
-- Up-to-date: /usr/local/include/ledger/select.h
-- Up-to-date: /usr/local/include/ledger/session.h
-- Up-to-date: /usr/local/include/ledger/stats.h
-- Up-to-date: /usr/local/include/ledger/stream.h
-- Up-to-date: /usr/local/include/ledger/temps.h
-- Up-to-date: /usr/local/include/ledger/timelog.h
-- Up-to-date: /usr/local/include/ledger/times.h
-- Up-to-date: /usr/local/include/ledger/token.h
-- Up-to-date: /usr/local/include/ledger/unistring.h
-- Up-to-date: /usr/local/include/ledger/utils.h
-- Up-to-date: /usr/local/include/ledger/value.h
-- Up-to-date: /usr/local/include/ledger/views.h
-- Up-to-date: /usr/local/include/ledger/xact.h
-- Up-to-date: /usr/local/include/ledger/system.hh
-- Installing: /usr/local/bin/ledger
-- Set runtime path of "/usr/local/bin/ledger" to "/usr/local/lib"
-- Up-to-date: /usr/local/share/man/man1/ledger.1

and here is the ldd:
$ ldd ledger
        linux-vdso.so.1 (0x00007fff5bbf9000)
        libledger.so.3 => /home/sergiu/ledger-3.3.2/libledger.so.3 (0x00007f957de9f000)
        libedit.so.2 => /lib/x86_64-linux-gnu/libedit.so.2 (0x00007f957de54000)
        libboost_filesystem.so.1.82.0 => /home/sergiu/miniconda3/envs/ldg-build/lib/libboost_filesystem.so.1.82.0 (0x00007f957de32000)
        libstdc++.so.6 => /home/sergiu/miniconda3/envs/ldg-build/lib/libstdc++.so.6 (0x00007f957dc1e000)
        libgcc_s.so.1 => /home/sergiu/miniconda3/envs/ldg-build/lib/libgcc_s.so.1 (0x00007f957dc04000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f957da12000)
        libmpfr.so.6 => /lib/x86_64-linux-gnu/libmpfr.so.6 (0x00007f957d98f000)
        libgmp.so.10 => /lib/x86_64-linux-gnu/libgmp.so.10 (0x00007f957d90b000)
        libboost_iostreams.so.1.82.0 => /home/sergiu/miniconda3/envs/ldg-build/lib/libboost_iostreams.so.1.82.0 (0x00007f957d8f3000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f957d7a4000)
        libtinfo.so.6 => /lib/x86_64-linux-gnu/libtinfo.so.6 (0x00007f957d774000)
        libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007f957d75a000)
        libboost_atomic.so.1.82.0 => /home/sergiu/miniconda3/envs/ldg-build/lib/./libboost_atomic.so.1.82.0 (0x00007f957d74e000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f957d744000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f957d721000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f957e228000)
        libz.so.1 => /home/sergiu/miniconda3/envs/ldg-build/lib/./libz.so.1 (0x00007f957d703000)
        libbz2.so.1.0 => /home/sergiu/miniconda3/envs/ldg-build/lib/./libbz2.so.1.0 (0x00007f957d6ef000)
        liblzma.so.5 => /home/sergiu/miniconda3/envs/ldg-build/lib/./liblzma.so.5 (0x00007f957d6bd000)
        libzstd.so.1 => /home/sergiu/miniconda3/envs/ldg-build/lib/./libzstd.so.1 (0x00007f957d5ad000)

Alexis

unread,
Dec 19, 2023, 12:59:04 PM12/19/23
to ledge...@googlegroups.com
Hi,

some of the things that you might try to resolve this are:

1. Disable use of libedit by appending -DHAVE_EDIT:BOOL=NO to the
./acprep call

2. Define LDFLAGS="-L$PATH_TO_NCURSES_LIBDIR -lncurses" in the
environment when running acprep hoping cmake will pick it up
properly.

3. Manually disable use of libedit in CMakeLists.txt by
adding the following below line 256¹
set(HAVE_EDIT 0)


Cheers
Alexis

¹ https://github.com/ledger/ledger/blob/master/CMakeLists.txt#L256

lipp f

unread,
Dec 19, 2023, 1:22:56 PM12/19/23
to Ledger
Thank you for all the help  Alexis.  Probably you didn't notice the previous message but the ncurses issue was resolved, and I can do the full build now. The issues are that the built seems to be without python, there is no python module under site-packages and make install puts the files in a wrong place.

Alexis

unread,
Dec 19, 2023, 1:41:43 PM12/19/23
to ledge...@googlegroups.com
Hi,

> I can run $ ./ledger --version and I'm getting "Ledger 3.3.2-20230330",

Posting the complete output of ./ledger --version is helpful as the
version info includes a note about Python support:

% ledger --version | head -2
Ledger 3.3.2-20230330, the command-line accounting tool
with support for gpg encrypted journals and with Python support

> which is great, but the python test, fails on "import ledger".

Seeing how you invoke Python, which version is run, and the actual
error message when "the python test fails on "import ledger" can be
insightful, e.g.:

% /usr/bin/python3
Python 3.9.6 (default, Nov 10 2023, 13:38:27)
[Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ledger
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'ledger'

Maybe you could do a complete clean build from within a shell started
with script(1) and reply to this mail with the output (ledger-build.log)
attached?

% script ledger-build.log
% ./acprep ....
% exit

Looking at the linked libraries of the ledger (ldd output) built on
your system I do not see any references to Python, which exist for me
on my machine (see below).

% otool -L $(which ledger)
~/.nix-profile/bin/ledger:
/nix/store/zm4a348a65ilcl35dg1sc5wmr98f0qnn-ledger-3.3.2/lib/libledger.3.dylib (compatibility version 3.0.0, current version 3.0.0)
/nix/store/3zkxk2nzf3b59fmdqi7s8fasl4asgx37-gpgme-1.23.0/lib/libgpgmepp.6.dylib (compatibility version 27.0.0, current version 27.0.0)
/nix/store/z0nnwdh4p692yvf3qgwgj3bn78w99q6y-python3-3.11.6/lib/libpython3.11.dylib (compatibility version 3.11.0, current version 3.11.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.60.1)
/nix/store/3zkxk2nzf3b59fmdqi7s8fasl4asgx37-gpgme-1.23.0/lib/libgpgme.11.dylib (compatibility version 44.0.0, current version 44.0.0)
/nix/store/sc9h2pf31m4pqbnq9h5f5yj0ccgr1hb6-libassuan-2.5.6/lib/libassuan.0.dylib (compatibility version 9.0.0, current version 9.6.0)
/nix/store/l455b10bq8vri2gzgy7jk5fzjh6q24b8-mpfr-4.2.1/lib/libmpfr.6.dylib (compatibility version 9.0.0, current version 9.1.0)
/nix/store/1mlfpdjs99nhkin3gi2ns37vggkskkr4-gmp-with-cxx-6.3.0/lib/libgmp.10.dylib (compatibility version 16.0.0, current version 16.0.0)
/nix/store/4w0d6ly44x9mczv4s0x26dyhisgshb01-libedit-20221030-3.1/lib/libedit.0.dylib (compatibility version 1.0.0, current version 1.70.0)
/nix/store/rd912bdihq9azqhmx37p39yp05mv8vca-boost-1.81.0/lib/libboost_date_time.dylib (compatibility version 0.0.0, current version 0.0.0)
/nix/store/rd912bdihq9azqhmx37p39yp05mv8vca-boost-1.81.0/lib/libboost_filesystem.dylib (compatibility version 0.0.0, current version 0.0.0)
/nix/store/rd912bdihq9azqhmx37p39yp05mv8vca-boost-1.81.0/lib/libboost_atomic.dylib (compatibility version 0.0.0, current version 0.0.0)
/nix/store/rd912bdihq9azqhmx37p39yp05mv8vca-boost-1.81.0/lib/libboost_system.dylib (compatibility version 0.0.0, current version 0.0.0)
/nix/store/rd912bdihq9azqhmx37p39yp05mv8vca-boost-1.81.0/lib/libboost_iostreams.dylib (compatibility version 0.0.0, current version 0.0.0)
/nix/store/rd912bdihq9azqhmx37p39yp05mv8vca-boost-1.81.0/lib/libboost_regex.dylib (compatibility version 0.0.0, current version 0.0.0)
/nix/store/rd912bdihq9azqhmx37p39yp05mv8vca-boost-1.81.0/lib/libboost_unit_test_framework.dylib (compatibility version 0.0.0, current version 0.0.0)
/nix/store/rd912bdihq9azqhmx37p39yp05mv8vca-boost-1.81.0/lib/libboost_python311.dylib (compatibility version 0.0.0, current version 0.0.0)
/nix/store/rd912bdihq9azqhmx37p39yp05mv8vca-boost-1.81.0/lib/libboost_nowide.dylib (compatibility version 0.0.0, current version 0.0.0)
/nix/store/0w070w3a2azyy1gs4mgskz9j3pq0g5dy-libcxxabi-16.0.6/lib/libc++abi.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/nix/store/jkp27cvkfzy264pgmwgry17rkyi50m3r-gettext-0.21.1/lib/libintl.8.dylib (compatibility version 12.0.0, current version 12.0.0)
/nix/store/a78xnmg223s3iffja69ydg6sswbwd3i3-libiconv-50/lib/libiconv.dylib (compatibility version 7.0.0, current version 7.0.0)
/nix/store/p5wr7bxrs2naa4rwy9sqs19rljr7g7qh-libcxx-16.0.6/lib/libc++.1.0.dylib (compatibility version 1.0.0, current version 1.0.0)

lipp f

unread,
Dec 19, 2023, 2:47:22 PM12/19/23
to Ledger
Giving up.

$ ./acprep clean
$ ./acprep configure  -DUSE_PYTHON=ON -DPython_ROOT_DIR=/home/sergiu/miniconda3/envs/ldg-build/
$ ./acprep make -- -DUSE_PYTHON=ON -DPython_ROOT_DIR=/home/sergiu/miniconda3/envs/ldg-build/

No errors whatsoever.

$ ./ledger

Ledger 3.3.2-20230330, the command-line accounting tool
without support for gpg encrypted journals and without Python support

Copyright (c) 2003-2023, John Wiegley.  All rights reserved.

Alexis

unread,
Dec 19, 2023, 3:32:30 PM12/19/23
to ledge...@googlegroups.com
Hi,

quite frankly I'm not particularly fond of acprep and prefer to use
the tools it wraps. Please find below the commands I use to cleanly
build ledger with Python support on macOS with a build environment
setup from nix flake and using cmake and make directly:

% rm ledger{,.so}
% rm -rf build
% cmake -Bbuild -S. -DUSE_PYTHON:BOOL=ON -DPython_ROOT_DIR=$(which python)/../../
% make -Cbuild -j8
% ls -lsa ./build/ledger{,.so}
428 -rwxr-xr-x 1 $USER staff 435664 Dec 19 21:27 ./build/ledger
5684 -rwxr-xr-x 1 $USER staff 5819184 Dec 19 21:27 ./build/ledger.so
% ./build/ledger --version | head -2
Ledger 3.3.2-20230330, the command-line accounting tool
without support for gpg encrypted journals and with Python support
% env PYTHONPATH=/does/not/exist python -c 'import ledger; print(ledger.__version__)'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'ledger'
% env PYTHONPATH=$PWD/build python -c 'import ledger; print(ledger.__version__)'
3.3.2

Not sure how helpful this is going to be yet the following works for me too:

% ./acprep clean
% ls -lsa ./ledger{,.so}
ls: cannot access './ledger': No such file or directory
ls: cannot access './ledger.so': No such file or directory
% ./acprep configure --python -- -DPython_ROOT_DIR=$(which python)/../../
% ./acprep make -j8
% ls -lsa ./ledger{,.so}
928 -rwxr-xr-x 1 $USER staff 948368 Dec 19 21:19 ./ledger
8916 -rwxr-xr-x 1 $USER staff 9126192 Dec 19 21:19 ./ledger.so
% ./ledger --version | head -2
Ledger 3.3.2-20230330, the command-line accounting tool
without support for gpg encrypted journals and with Python support
% PYTHONPATH=. python -c 'import ledger; print(ledger.__version__)'
3.3.2

🤞

lipp f

unread,
Dec 19, 2023, 4:30:46 PM12/19/23
to Ledger
A big thank you  Alexis. It works indeed. After make install I had to add /home/sergiu/miniconda3/envs/ldg-build/lib to ld.so.conf and I can run python  ./python/demo.py
Welcome to the Ledger.Python demo!
Demo completed successfully.
Now, if I understand this correctly, the python module is in ledger.so and whenever I want to "import ledger" I have to setup  PYTHONPATH to the location where ledger.so is. Am I rigth?


Alexis

unread,
Dec 19, 2023, 5:16:00 PM12/19/23
to ledge...@googlegroups.com
Yay!

Glad to hear that you managed to get it working.
Welcome to the quirky and wonderful world of Ledger Python! :)

I've been using Ledger Python for several years time, happy to answer
questions and take inspiration for future API development from your
experience with it.

To answer your question, yes, as long as ledger.so is compiled properly
for the architecture and system you expect it to run on, you can place
it were you like and tell Python about its location using PYTHONPATH
or other means Python offers to load modules.

If you have the time and would like to give back, some feedback on
what would have helped you in terms of documentation or examples to
get Python Ledger installed would be appreciated.


Cheers
Alexis

lipp f

unread,
Dec 19, 2023, 5:37:41 PM12/19/23
to Ledger
sure. I also was thinking to document all steps required to install ledger in a conda environment.
Message has been deleted

lipp f

unread,
Dec 19, 2023, 7:09:30 PM12/19/23
to Ledger
I noticed something strange. I do this:
$ PYTHONPATH=lib/ python
>>> import ledger
>>> j_file = r"/mnt/e/Data/Invest/data/ledger/xxxxxxxxxx.j"
>>> journal = ledger.read_journal(j_file)
>>> journal = ledger.read_journal(j_file)


Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: Assertion failed in "/home/sergiu/ledger-3.3.2/src/session.cc", line 183:std::size_t ledger::session_t::read_data(const string&): xact_count == journal->xacts.size()
>>>
I can only read the  journal once.

Alexis

unread,
Dec 20, 2023, 3:40:24 AM12/20/23
to ledge...@googlegroups.com
Hi

Ledger's internal session handling is getting in your way here.
The way it is has been bothering me for quite some as it does
not work as I think it should, but that is for another time and debate.

In order to read journals multiple times they need to be closed
in between. The following works for me:

% python
>>> import ledger
>>> journal = ledger.read_journal('test/input/drewr3.dat')
>>> len(journal)
11
>>> ledger.close_journal_files()
>>> journal = ledger.read_journal('test/input/drewr3.dat')
>>> len(journal)
11

May I ask for what purpose you plan to use Ledger Python and would
you be okay with me contacting you outside of this list?


Best
Alexis
Reply all
Reply to author
Forward
0 new messages