[GNC] Python bindings issue

Jim DeLaHunt list+gnucash at jdlh.com
Tue Aug 13 20:16:16 EDT 2024


On 2024-08-13 15:14, Gere Kiss Zsolt wrote:
> Hi Jim,
>
> and thanks for the response.
>
> > I too am someone who has used GnuCash from the UI from several years,
> and is now starting to try using the Python bindings. I am on macOS
> rather than Linux.
>
> Did you succeed to import the Python bindings with  `import gnucash`?

That has succeeded sometimes, and failed sometimes, but presently it 
succeeds. (Using the MacPorts distribution of gnucash @5.8_1+docs on macOS.)

I can also, for example, add a security to a book file by using the 
GncCommodity() class. This sample code worked for me:

>>> import gnucash
>>> FILE = "file://./test_book_1.gnucash"
>>> session = gnucash.gnucash_core.Session(FILE)
>>> book = session.book
>>> comms = book.get_table()
>>> qqq = gnucash.gnucash_core.GncCommodity(book, 'QQQ_fullname', 'MySecurityType', 'QQQ', 'QQQ_qsip', 100)
>>> comms.insert(qqq)
>>> session.end()
>>> session.destroy()
>>> quit()


> >  Suggestion 1: is the OS package python3-gnucash installed on your 
> system?
>
> Sure, as I mentioned:
>
>     Other gnucash related OS packages:
>
>       * gnucash-common
>       * gnucash-docs
>       * *python3-gnucash*
>
Sorry, I guess I did not follow your meaning. I read you as saying that 
those packages, but not that those packages were actually installed on 
your system.


> > Suggestion 2: what info about python3-gnucash does the apt system
> display (in the same way it displayed information about the package
> gnucash)?
>
> Package: python3-gnucash
> Version: 1:4.8-1build2
> State: installed
> Section: universe/python
> Maintainer: Ubuntu Developers <ubuntu-devel-discuss at lists.ubuntu.com>
> Architecture: amd64
> Depends: libc6 (>= 2.14), libglib2.0-0 (>= 2.12.0), libpython3.10 (>= 
> 3.10.0), python3 (< 3.11), python3 (>= 3.10~), python3:any
>
> As you can see from Depends, it installs bindings for python3 >= 3.10~ 
> < 3.11.
> 3.10.12 is the version of Python3 installed on my OS, so this should 
> conform (no wonder, since it is an OS package). Maybe some other 
> libraries (like libc6?, etc.) are incompatible between gnucash 
> and python3-gnucash?
You have reached the limit of my knowledge, especially concerning 
GnuCash on Linux. Sorry.
> Can you do `import gnucash` from a Python REPL?
Again, yes.  Thus you can be confident that it has worked for someone 
somewhere at some time.

Best regards,
      —Jim DeLaHunt


More information about the gnucash-user mailing list