notcurses icon indicating copy to clipboard operation
notcurses copied to clipboard

Can't get the Python bindings to work

Open trygveaa opened this issue 2 years ago • 4 comments

Hi! I can't get the Python bindings to work, and I'm not sure if I'm doing something wrong or if they are broken. If I try to run for example the 002-hello-world.py example I get ImportError: cannot import name 'Notcurses' from 'notcurses'.

If I change the import to from notcurses.notcurses import Notcurses that import works, but then I get AttributeError: 'Ncplane' object has no attribute 'putstr'. The same goes for the other examples, e.g. set_bg_rgb8_clipped and dim_yx are also missing from Ncplane, and NcChannels is missing entirely.

If I look at the installed python files, I see that __init__.py is completely empty which explains why I had to change the import to import directly from the notcurses.py file. That file has Ncplane and some other things, but the attributes and classes mentioned above are missing from it and nowhere to be found.

This happens both with the Arch package (which I see is outdated), and if I try to build it myself. I also tried to install it with pip, but the wheel compile of notcurses failed there. I downloaded the .tar.gz from pypi however, and see the same things missing in the .py files in that package.

trygveaa avatar Feb 15 '22 22:02 trygveaa

Same here running Gentoo. I installed notcurses via emerge and installed the python bindings via pip. Gentoo's current version is still 3.0.5. Thinking I might need a newer notcurses I copied the notcurses ebuild to my local repository and bumped the version number. That causes Gentoo to download, build and install the newer source, 3.0.7. That didn't seem to help.

I did not try installing the python bindings with pip b/c I was using Gentoo's package manager to install the notcurses library itself.

kc8rwr avatar Feb 22 '22 19:02 kc8rwr

Same thing here, I've tried it in Docker and also local installs. The Python demo also looks like it's only partially working. Well it looks like I have to try and fix it my self.

ulio7410 avatar Jul 24 '22 16:07 ulio7410

Hello, I'm also trying to use the python bindings. As noted in https://github.com/dankamongmen/notcurses/issues/2670 it seems there are two APIs, the old cffi bindings, and some newer more pythonic bindings (some discussion in https://github.com/dankamongmen/notcurses/issues/1154 and https://github.com/dankamongmen/notcurses/pull/109). You can switch the Archlinux package to use the new bindings by changing the cd ../cffi on line 38 of the PKGBUILD to cd ../python; then the examples in python/examples seem to work.

Anyway it seems like both bindings are pretty incomplete (I can't seem to find a way to access the constants for checking input events for example). It also appears there is some stuff for generating documentation with sphinx but I can't find any scripts or processes set up to build it nor can I find it hosted anywhere on the internet (I was able to partially build it manually however).

@dankamongmen Would you be interested in help with the python API? I'm willing to help set up a build process for the python binding docs + hosting on read-the-docs or similar. I'm not totally sure I want to use this library yet (it's an awesome library! Thank you so much for your awesome work, just not sure it fits my needs well at the moment); but if I do I would be interested in helping fill out the python bindings further including getting some unit test infrastructure set up. Do you have any thoughts or opinions?

gandalf3 avatar Aug 09 '22 05:08 gandalf3

If you think you can improve igo's bindings, then go for it. They're currently hosted here and dank appears to have stopped actively working on this project but still reviewing and accepting any PRs that come in. The first step would be to replace the old bindings so there's only one. It will lead to easier review to do that and then provide any updates you think might be needed. A workaround you could use for now is to utilize pythonc so you can use notcurses natively without bindings. The python bindings would be easier but at least you know you're getting more of a perf boost with pythonc.

WSLUser avatar Oct 20 '22 22:10 WSLUser