trainman419 / python-cec

Other
170 stars 42 forks source link

Failed Installing python-CEC #12

Closed brusc closed 6 years ago

brusc commented 8 years ago

I'm running on a RP2 running Raspbian Jessie. I'm getting an error when I try to use the command sudo pip install cec command.

Failed to build cec
Installing collected packages: cec
  Running setup.py install for cec ... error
    Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/     tmp/pip-build-f7e5ro0h/cec/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read     ().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-lv2te9fx-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-armv7l-3.4
    arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -     Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -Iinclude -I/usr/include/python3.4m -c      cec.cpp -o build/temp.linux-armv7l-3.4/cec.o
    cec.cpp: In function ‘PyObject* set_stream_path(PyObject*, PyObject*)’:
    cec.cpp:411:25: error: ‘PyInt_Check’ was not declared in this scope
           if(PyInt_Check(arg)) {
                             ^
    cec.cpp:412:39: error: ‘PyInt_AsLong’ was not declared in this scope
              long arg_l = PyInt_AsLong(arg);
                                           ^
    cec.cpp:420:35: error: ‘PyString_Check’ was not declared in this scope
           } else if(PyString_Check(arg)) {
                                       ^
    cec.cpp:421:46: error: ‘PyString_AsString’ was not declared in this scope
              char * arg_s = PyString_AsString(arg);
                                                  ^
    cec.cpp: In function ‘PyObject* initcec()’:
    cec.cpp:671:7: error: return-statement with no value, in function returning ‘PyObject* {aka      _object*}’ [-fpermissive]
           return;
           ^
    cec.cpp:681:31: error: return-statement with no value, in function returning ‘PyObject* {aka      _object*}’ [-fpermissive]
        if(PyType_Ready(dev) < 0 ) return;
                                   ^
    cec.cpp:683:50: error: ‘Py_InitModule’ was not declared in this scope
        PyObject * m = Py_InitModule("cec", CecMethods);
                                                      ^
    cec.cpp:685:20: error: return-statement with no value, in function returning ‘PyObject* {aka      _object*}’ [-fpermissive]
        if( m == NULL ) return;
                        ^
    error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1

If I try sudo pip2 install cec, it installs correctly, but when calling a python script it fails with

sudo python /var/opt/homeassistant/bruh2/cecscript/allon.py
Traceback (most recent call last):
  File "/var/opt/homeassistant/bruh2/cecscript/allon.py", line 4, in <module>
    cec.init()
IOError: CEC failed to open ▒▒▒▒

Libcec3.0 is installed and working correctly.

libCEC version: 3.0.1,  compiled on Fri Jul  3 19:20:43 UTC 2015 by pbuilder@mgo                     rven-pc.thefacebook.com on Linux 3.16.0-41-generic (armv7l), features: P8_USB, P                     8_detect, 'RPi'
Found devices: 1

device:              1
com port:            RPI
vendor id:           2708
product id:          1001
firmware version:    1
type:                Raspberry Pi

Any ideas?

trainman419 commented 8 years ago

It looks like you're trying to build against python 3, but this library is written as a C extension for python 2.7. It looks like the extension API for python 3 has changed.

trainman419 commented 8 years ago

It looks like the port to python3 isn't too difficult, but it's not going to be quick. In particular module initialization has changed a lot: https://docs.python.org/2/howto/cporting.html

I've started the port on the https://github.com/trainman419/python-cec/tree/devel branch, and ported everything except the module init.

If you want to work on porting the module init, that would be helpful; otherwise I'll get around to it at some point.

brusc commented 8 years ago

Thanks for the info! So when I install via pip2 it installs fine. I have no issue with using python2.7, but python-cec isn't working as I'm getting the CEC failed to open statement. Is that related to this python issue?

trainman419 commented 8 years ago

Installing with python2 / pip2 should work. I don't have a machine with libcec3 and an adapter, so I can't confirm that the recent patches to support libcec3 actually work.

I'm also not sure if the raspberry Pi 2 has CEC hardware, or if it's supported by libcec. If you can confirm that the CEC hardware works with the default cec-client command that comes with libcec, that establishes a baseline and indicates that the bug is in this python wrapper.

michaelarnauts commented 8 years ago

The rpi supports cec-client.

ghost commented 7 years ago

Ping on this issue. Depending on what distro you've got installed, libcec will be compiled without Raspberry Pi support (!).

Double check that cec-client -s works correctly. I can confirm that the Raspberry Pi 2 has the same Pulse8 CEC adapter onboard.

What else is required for this issue to be closed?

trainman419 commented 7 years ago

@voltagex thanks for confirming that the hardware on the Pi 2 is supported!

And yes, one of the reasons that I provided binaries of libcec for the raspbian on the Pi 1 is precisely because the originals were built without Raspberry Pi support.

There are three different issues wrapped up here

  1. Confirming that the Raspberry Pi 2 has CEC hardware is supported by libcec
  2. Confirming that python-cec library is compatible with libcec3 (possibly specific to the Pi2)
  3. Porting python-cec to be compatible with python3

You've clearly addressed (1); if you're using libcec3 that would also confirm (2).

I should probably open a separate ticket for (3)

trainman419 commented 7 years ago

@voltagex if you have specific notes about which distros do and don't have Raspberry Pi support compiled in, I can also include that in my README.

ghost commented 7 years ago

@trainman419 thanks for the quick response. Unfortunately I'm not sure what distros do and don't have Pi support compiled in. I'm fairly sure I had to compile libcec et al for Debian Jessie armhf - Raspbian should be set up properly though.

The correct way to find out if it's compiled with Pi support is:

$ cec-client -i
libCEC version: 3.1.0, compiled on Linux-4.1.17-v7+ ... , features: P8_USB, DRM, P8_detect, randr, RPi

(also confirming I'm using libcec 3 from Jessie backports - 3.1.0+dfsg1-4~bpo8+2)

ghost commented 7 years ago

I'm now using libcec 4, compiled on a Raspberry Pi 2 successfully with your library. Ping on Python 3 support, it's blocking me using this with 0mq (Python 3.5+ is all kinds of broken on Jessie, but oh well)

michaelarnauts commented 7 years ago

I've compiled some .deb packages for rpi3 by following these steps:

I couldn't follow them exactly, since they gave some issues. Maybe I'll write a guide sometime. You could use my binaries from here https://github.com/michaelarnauts/cec-mqtt-bridge/tree/master/libcec if you don't want to do all the compiling. It's based on the latest libcec4 code (https://github.com/Pulse-Eight/libcec/commit/12fa2750f9fae944956ba0adc2d0298165f975fb). The python3 library seems to work fine.

ghost commented 7 years ago

Thanks for the info, seems we've been trying to do something very similar.

On 29 December 2016 at 22:43, Michaël Arnauts notifications@github.com wrote:

I've compiled some .deb packages for rpi3 by following these steps:

I couldn't follow them exactly, since they gave some issues. Maybe I'll write a guide sometime. You could use my binaries from here https://github.com/michaelarnauts/cec-mqtt-bridge/tree/master/libcec if you don't want to do all the compiling. It's based on the latest libcec4 code (Pulse-Eight/libcec@12fa275 https://github.com/Pulse-Eight/libcec/commit/12fa2750f9fae944956ba0adc2d0298165f975fb). The python3 library seems to work fine.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/trainman419/python-cec/issues/12#issuecomment-269618899, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJvT9RLPRpImICPgaJgVP7FQ82w8NOLks5rM5zLgaJpZM4H9UHa .

tmcneal commented 7 years ago

I've got a fork going which completes the Python3 upgrade that @trainman419 started last year. I haven't fully tested it yet but it seems to be working for me (tested on a RP3): https://github.com/tmcneal/python-cec/tree/devel

trainman419 commented 6 years ago

Python3 support has merged with #20.