0

I have rpi 1 model b with stretch installed. I want to use python cec library. First I tried to install it.

sudo apt install python-libcec

But fails to import cec ::

Python 2.7.13 (default, Jan 19 2017, 14:48:08)
[GCC 6.3.0 20170124] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cec
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/cec/__init__.py", line 21, in <module>
    _cec = swig_import_helper()
  File "/usr/lib/python2.7/dist-packages/cec/__init__.py", line 20, in swig_import_helper
    return importlib.import_module('_cec')
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named _cec

Then I tried to install by pip :: sudo apt install python-pip libcec4-dev

But sudo pip install cec fails with this error ::

Collecting cec
  Using cached cec-0.2.5.tar.gz
Building wheels for collected packages: cec
  Running setup.py bdist_wheel for cec ... error
  Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-fXgVtd/cec/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpdR4oC1pip-wheel- --python-tag cp27:
  running bdist_wheel
  running build
  running build_ext
  building 'cec' extension
  creating build
  creating build/temp.linux-armv6l-2.7
  arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-9xgeTe/python2.7-2.7.13=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Iinclude -I/usr/include/python2.7 -c cec.cpp -o build/temp.linux-armv6l-2.7/cec.o
  cec.cpp: In function ‘std::__cxx11::list<CEC::cec_adapter> get_adapters()’:
  cec.cpp:102:27: error: ‘class CEC::ICECAdapter’ has no member named ‘FindAdapters’; did you mean ‘PingAdapter’?
   #define CEC_FIND_ADAPTERS FindAdapters
                             ^
  cec.cpp:153:29: note: in expansion of macro ‘CEC_FIND_ADAPTERS’
      int count = CEC_adapter->CEC_FIND_ADAPTERS(dev_list, cec_count);
                               ^~~~~~~~~~~~~~~~~
  cec.cpp:102:27: error: ‘class CEC::ICECAdapter’ has no member named ‘FindAdapters’; did you mean ‘PingAdapter’?
   #define CEC_FIND_ADAPTERS FindAdapters
                             ^
  cec.cpp:158:28: note: in expansion of macro ‘CEC_FIND_ADAPTERS’
         count = CEC_adapter->CEC_FIND_ADAPTERS(dev_list, cec_count);
                              ^~~~~~~~~~~~~~~~~
  cec.cpp: In function ‘void initcec()’:
  cec.cpp:657:19: error: ‘CEC::ICECCallbacks {aka struct CEC::ICECCallbacks}’ has no member named ‘CBCecLogMessage’; did you mean ‘logMessage’?
      CEC_callbacks->CBCecLogMessage = log_cb;
                     ^~~~~~~~~~~~~~~
  cec.cpp:658:19: error: ‘CEC::ICECCallbacks {aka struct CEC::ICECCallbacks}’ has no member named ‘CBCecKeyPress’; did you mean ‘keyPress’?
      CEC_callbacks->CBCecKeyPress = keypress_cb;
                     ^~~~~~~~~~~~~
  cec.cpp:659:19: error: ‘CEC::ICECCallbacks {aka struct CEC::ICECCallbacks}’ has no member named ‘CBCecCommand’
      CEC_callbacks->CBCecCommand = command_cb;
                     ^~~~~~~~~~~~
  cec.cpp:660:19: error: ‘CEC::ICECCallbacks {aka struct CEC::ICECCallbacks}’ has no member named ‘CBCecConfigurationChanged’; did you mean ‘configurationChanged’?
      CEC_callbacks->CBCecConfigurationChanged = config_cb;
                     ^~~~~~~~~~~~~~~~~~~~~~~~~
  cec.cpp:661:19: error: ‘CEC::ICECCallbacks {aka struct CEC::ICECCallbacks}’ has no member named ‘CBCecAlert’
      CEC_callbacks->CBCecAlert = alert_cb;
                     ^~~~~~~~~~
  cec.cpp:662:19: error: ‘CEC::ICECCallbacks {aka struct CEC::ICECCallbacks}’ has no member named ‘CBCecMenuStateChanged’; did you mean ‘menuStateChanged’?
      CEC_callbacks->CBCecMenuStateChanged = menu_cb;
                     ^~~~~~~~~~~~~~~~~~~~~
  cec.cpp:663:19: error: ‘CEC::ICECCallbacks {aka struct CEC::ICECCallbacks}’ has no member named ‘CBCecSourceActivated’; did you mean ‘sourceActivated’?
      CEC_callbacks->CBCecSourceActivated = activated_cb;
                     ^~~~~~~~~~~~~~~~~~~~
  error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for cec
  Running setup.py clean for cec
Failed to build cec
Installing collected packages: cec
  Running setup.py install for cec ... error
    Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-fXgVtd/cec/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-qPO7Pl-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_ext
    building 'cec' extension
    creating build
    creating build/temp.linux-armv6l-2.7
    arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-9xgeTe/python2.7-2.7.13=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Iinclude -I/usr/include/python2.7 -c cec.cpp -o build/temp.linux-armv6l-2.7/cec.o
    cec.cpp: In function ‘std::__cxx11::list<CEC::cec_adapter> get_adapters()’:
    cec.cpp:102:27: error: ‘class CEC::ICECAdapter’ has no member named ‘FindAdapters’; did you mean ‘PingAdapter’?
     #define CEC_FIND_ADAPTERS FindAdapters
                               ^
    cec.cpp:153:29: note: in expansion of macro ‘CEC_FIND_ADAPTERS’
        int count = CEC_adapter->CEC_FIND_ADAPTERS(dev_list, cec_count);
                                 ^~~~~~~~~~~~~~~~~
    cec.cpp:102:27: error: ‘class CEC::ICECAdapter’ has no member named ‘FindAdapters’; did you mean ‘PingAdapter’?
     #define CEC_FIND_ADAPTERS FindAdapters
                               ^
    cec.cpp:158:28: note: in expansion of macro ‘CEC_FIND_ADAPTERS’
           count = CEC_adapter->CEC_FIND_ADAPTERS(dev_list, cec_count);
                                ^~~~~~~~~~~~~~~~~
    cec.cpp: In function ‘void initcec()’:
    cec.cpp:657:19: error: ‘CEC::ICECCallbacks {aka struct CEC::ICECCallbacks}’ has no member named ‘CBCecLogMessage’; did you mean ‘logMessage’?
        CEC_callbacks->CBCecLogMessage = log_cb;
                       ^~~~~~~~~~~~~~~
    cec.cpp:658:19: error: ‘CEC::ICECCallbacks {aka struct CEC::ICECCallbacks}’ has no member named ‘CBCecKeyPress’; did you mean ‘keyPress’?
        CEC_callbacks->CBCecKeyPress = keypress_cb;
                       ^~~~~~~~~~~~~
    cec.cpp:659:19: error: ‘CEC::ICECCallbacks {aka struct CEC::ICECCallbacks}’ has no member named ‘CBCecCommand’
        CEC_callbacks->CBCecCommand = command_cb;
                       ^~~~~~~~~~~~
    cec.cpp:660:19: error: ‘CEC::ICECCallbacks {aka struct CEC::ICECCallbacks}’ has no member named ‘CBCecConfigurationChanged’; did you mean ‘configurationChanged’?
        CEC_callbacks->CBCecConfigurationChanged = config_cb;
                       ^~~~~~~~~~~~~~~~~~~~~~~~~
    cec.cpp:661:19: error: ‘CEC::ICECCallbacks {aka struct CEC::ICECCallbacks}’ has no member named ‘CBCecAlert’
        CEC_callbacks->CBCecAlert = alert_cb;
                       ^~~~~~~~~~
    cec.cpp:662:19: error: ‘CEC::ICECCallbacks {aka struct CEC::ICECCallbacks}’ has no member named ‘CBCecMenuStateChanged’; did you mean ‘menuStateChanged’?
        CEC_callbacks->CBCecMenuStateChanged = menu_cb;
                       ^~~~~~~~~~~~~~~~~~~~~
    cec.cpp:663:19: error: ‘CEC::ICECCallbacks {aka struct CEC::ICECCallbacks}’ has no member named ‘CBCecSourceActivated’; did you mean ‘sourceActivated’?
        CEC_callbacks->CBCecSourceActivated = activated_cb;
                       ^~~~~~~~~~~~~~~~~~~~
    error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-fXgVtd/cec/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-qPO7Pl-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-fXgVtd/cec/
1

Refering to this and I would simply do:

wget http://packages.namniart.com/repos/namniart.key -O - | sudo apt-key add -
sudo sh -c 'echo "deb http://packages.namniart.com/repos/pi wheezy main" > /etc/apt/sources.list.d/libcec.list'
sudo apt-get update
sudo apt-get install python-dev build-essential libcec-dev cec-utils

and then finally install with pip:

pip install cec

Should solve your problem.

0

Unfortunately library provided in stretch release of raspbian also looks like faulty. The package for regular Debian release contains additional file _cec.{architecture_name}.so, which would normally be loaded. This file is missing in rpi, thus "ImportError: No module named _cec" is shown.

I think we need to compile this library from source as described here: https://github.com/Pulse-Eight/libcec/blob/master/docs/README.raspberrypi.md

PS: the other answer suggests to install library with similar name but this pycec library (https://github.com/trainman419/python-cec) is just a wrapper around libcec. libcec contains its own python bindings (https://github.com/Pulse-Eight/libcec) and these are these bindings that are not working for OP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.