jquast / blessed

Blessed is an easy, practical library for making python terminal apps
http://pypi.python.org/pypi/blessed
MIT License
1.18k stars 71 forks source link

Initialization of blessed fails on debian due to curse module #215

Closed aperiodicchain closed 3 years ago

aperiodicchain commented 3 years ago

Hi,

on a fresh install (Raspberry 4B, latest raspbian (Debian version 10.10), python 3.9) I get NameError: name '_curses' is not defined on line import blessed.

to replicate:

pyenv install 3.9.6 # (tried also with 3.8 and 3.7)
pip install blessed
...
python3: import blessed

errors:

File "/home/pi/.cache/pypoetry/virtualenvs/iotstack-ux5BfMTt-py3.9/lib/python3.9/site-packages/blessed/keyboard.py", line 18, in <module>
    import curses
  File "/home/pi/.pyenv/versions/3.9.6/lib/python3.9/curses/__init__.py", line 56, in <module>
    from .has_key import has_key
  File "/home/pi/.pyenv/versions/3.9.6/lib/python3.9/curses/has_key.py", line 11, in <module>
    _curses.KEY_A1: 'ka1',
NameError: name '_curses' is not defined

I have seen #99 and the suggestion therein to rebuild python which for many can be quite troublesome. Is there any more straightforward solution (maybe adding the correct dependency in pip install) since I assume many users will hit this issue "by default".

avylove commented 3 years ago

It seems you don't have the Python curses C libraries installed. I'm not sure if that's intentional or they were moved to a separate package. A quick search shows people have been using Curses with Python on Raspbian, but there are some instances of people getting the same error as you. Curses is considered optional in CPython and won't be built if disabled or the curses libraries can't be found during the build. Can you ask in the Raspbian forums to see if you can get a definitive answer?

If it was intentional, which would surprise me, we can look at some alternative solutions like we have on Windows. Out of curiosity, what is the value of the TERM environment variable in your environment?

jquast commented 3 years ago

@aperiodicchain when installing python with pyenv (good for you!) it is compiling python from source and linking with the libraries available at that time -- Your system most certainly has curses, but probably not the development headers, debian splits those into another package for every library.

I think the solution is,

pyenv uninstall 3.9.6
sudo apt-get install libncurses5-dev
pyenv install 3.9.6

best wishes & enjoy

avylove commented 3 years ago

Ah, that makes sense. Sorry, I missed pyenv in the question and didn't realize it compiled from source.

aperiodicchain commented 3 years ago

@jquast this was the underlying issue and resolution spot on. It works fine now :) Thanks a lot for you help!

aperiodicchain commented 3 years ago

solution: install libncurses5-dev before compiling python from pyenv