spatialaudio/python-sounddevice

cffi.api.CDefError, unable to get started

Closed this issue · 8 comments

$ python3 -m pip install sounddevice --user
Downloading/unpacking sounddevice
  Downloading sounddevice-0.3.5-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): CFFI in /usr/lib/python3/dist-packages (from sounddevice)
Requirement already satisfied (use --upgrade to upgrade): pycparser in /usr/lib/python3/dist-packages (from CFFI->sounddevice)
Installing collected packages: sounddevice
Successfully installed sounddevice
Cleaning up...

$ python3 -m sounddevice
Traceback (most recent call last):
  File "/usr/lib/python3.4/runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.4/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/fiol/.local/lib/python3.4/site-packages/sounddevice.py", line 313, in <module>
    """)
  File "/usr/lib/python3/dist-packages/cffi/api.py", line 104, in cdef
    self._parser.parse(csource, override=override, packed=packed)
  File "/usr/lib/python3/dist-packages/cffi/cparser.py", line 157, in parse
    self._internal_parse(csource)
  File "/usr/lib/python3/dist-packages/cffi/cparser.py", line 169, in _internal_parse
    '%s ..." for now (literally)' % key)
cffi.api.CDefError: only supports the syntax "#define paUInt8 ..." for now (literally)

Then I found that maybe I had an outdated CFFI installed (which comes with my rather old distribution) so I installed the libffi-dev package and...

$ python3 -m pip install cffi --user --upgrade
Downloading/unpacking cffi from https://pypi.python.org/packages/0a/f3/686af8873b70028fccf67b15c78fd4e4667a3da995007afc71e786d61b0a/cffi-1.8.3.tar.gz#md5=c8e877fe0426a99d0cf5872cf2f95b27
  Downloading cffi-1.8.3.tar.gz (403kB): 403kB downloaded
  Running setup.py (path:/tmp/pip_build_fiol/cffi/setup.py) egg_info for package cffi
    
Downloading/unpacking pycparser from https://pypi.python.org/packages/be/64/1bb257ffb17d01f4a38d7ce686809a736837ad4371bcc5c42ba7a715c3ac/pycparser-2.17.tar.gz#md5=ca98dcb50bc1276f230118f6af5a40c7 (from cffi)
  Downloading pycparser-2.17.tar.gz (231kB): 231kB downloaded
  Running setup.py (path:/tmp/pip_build_fiol/pycparser/setup.py) egg_info for package pycparser
    
    warning: no previously-included files matching 'yacctab.*' found under directory 'tests'
    warning: no previously-included files matching 'lextab.*' found under directory 'tests'
    warning: no previously-included files matching 'yacctab.*' found under directory 'examples'
    warning: no previously-included files matching 'lextab.*' found under directory 'examples'
Installing collected packages: cffi, pycparser
  Running setup.py install for cffi
    building '_cffi_backend' extension
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -DUSE__THREAD -I/usr/include/python3.4m -c c/_cffi_backend.c -o build/temp.linux-x86_64-3.4/c/_cffi_backend.o
    x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.4/c/_cffi_backend.o -lffi -o build/lib.linux-x86_64-3.4/_cffi_backend.cpython-34m.so
    
  Running setup.py install for pycparser
    
    warning: no previously-included files matching 'yacctab.*' found under directory 'tests'
    warning: no previously-included files matching 'lextab.*' found under directory 'tests'
    warning: no previously-included files matching 'yacctab.*' found under directory 'examples'
    warning: no previously-included files matching 'lextab.*' found under directory 'examples'
    Build the lexing/parsing tables
Successfully installed cffi pycparser
Cleaning up...
$ python3 -m sounddevice
  0 HDA Intel HDMI: 0 (hw:0,3), ALSA (0 in, 8 out)
  1 HDA Intel HDMI: 1 (hw:0,7), ALSA (0 in, 8 out)
  2 HDA Intel HDMI: 2 (hw:0,8), ALSA (0 in, 8 out)
  3 HDA Intel PCH: ALC292 Analog (hw:1,0), ALSA (2 in, 2 out)
  4 hdmi, ALSA (0 in, 8 out)
  5 pulse, ALSA (32 in, 32 out)
* 6 default, ALSA (32 in, 32 out)
$ 

So... May I suggest that sounddevice (or its documentation) is updated to reflect the dependency on a specific version of CFFI?
Thanks!

Thanks, this error looks very much like what is mentioned in #46 (comment) and jromang/picochess#219.

And it looks like a reeeeeally old version of CFFI.

@antonio-fiol Could you please check which exact version was installed in your old distribution?
BTW, which version of which distribution is that?

It would be interesting to know at which exact CFFI version this problem is solved, then I can add it to setup.py and a new version of CFFI would be installed automatically if the locally installed one is too old.

some picochess users had this on their Raspberry (raspbian jessie) too.
So, this "reeeeally old cffi" is still in use even with relative new jessie system :-(

in our requirement.txt i use this now (and the problem is solved):
cffi==1.8.3
cryptography==1.5.2

@LocutusOfPenguin Good to know that it works with CFFI version 1.8.3, but could you please tell me which is the version that does not work?

i knew y gonna ask me that...but im not sure ;-)
I saw this (since jessie is based on debian):
https://packages.debian.org/search?keywords=python-cffi

and i think, its 0.8.6 (but not sure!). Im relative sure, its a 0.x version...It was really old.
This "voice issue" from picochess costed me alot of time and im happy, i get it to work for our users...I dont want to go backwards again ;-)

Thanks Matthias. The reported attempt was on a Ubuntu 14.04 system (yes, I
know I should have upgraded!) which included the python-cffi package
version 0.8.2. Upgrading via pip to use 1.8.3 fixed the issue, but I have
not tested any intermediate versions.

The distribution-packaged version on my raspberry pi running an updated
OSMC is 0.8.6. Even though that is my target runtime, I did not test it
there because it was failing on my laptop, and 1.8.3 worked, so I installed
1.8.3 on the Pi as well, and it worked.

On Tue, Nov 8, 2016 at 11:31 AM, Matthias Geier notifications@github.com
wrote:

Thanks, this error looks very much like what is mentioned in #46 (comment)
#46 (comment)
and jromang/picochess#219
jromang/picochess#219.

And it looks like a reeeeeally old version of CFFI.

@antonio-fiol https://github.com/antonio-fiol Could you please check
which exact version was installed in your old distribution?
BTW, which version of which distribution is that?

It would be interesting to know at which exact CFFI version this problem
is solved, then I can add it to setup.py and a new version of CFFI would
be installed automatically if the locally installed one is too old.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#49 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AWOtcdr0xlARDzvN53iG73hAXfmnbudAks5q8E-fgaJpZM4KrAuI
.

OK, thanks for the feedback. I tried some old CFFI versions and found out that it starts to work with version 1.0.

I've added a requirement for CFFI>=1.0 in #50.

@antonio-fiol @LocutusOfPenguin Can you please uninstall CFFI and try installing the version of sounddevice from #50 on your old distributions?

I am not really comfortable with git yet, and much less building and installing my own (or local) python packages. That said, I think the issue is fixed on branch issue-49. Just to double-check, here's what I did:

$ pip3 uninstall sounddevice cffi pycparser
$ git clone https://github.com/spatialaudio/python-sounddevice.git
python-sounddevice$ git checkout origin/issue-49
Note: checking out 'origin/issue-49'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD is now at 653f3ec... Require at least CFFI version 1.0

Wow... I never had my head detached before... ;-)

python-sounddevice$ ./make_dist.sh 
python-sounddevice/dist$ pip3 install sounddevice-0.3.5-py2.py3-none-any.whl --user
Unpacking ./sounddevice-0.3.5-py2.py3-none-any.whl
Downloading/unpacking CFFI>=1.0 (from sounddevice==0.3.5)
  Downloading cffi-1.8.3.tar.gz (403kB): 403kB downloaded
  Running setup.py (path:/tmp/pip_build_fiol/CFFI/setup.py) egg_info for package CFFI

Requirement already satisfied (use --upgrade to upgrade): pycparser in /usr/lib/python3/dist-packages (from CFFI>=1.0->sounddevice==0.3.5)
Installing collected packages: sounddevice, CFFI
  Running setup.py install for CFFI
    building '_cffi_backend' extension
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -DUSE__THREAD -I/usr/include/python3.4m -c c/_cffi_backend.c -o build/temp.linux-x86_64-3.4/c/_cffi_backend.o
    x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.4/c/_cffi_backend.o -lffi -o build/lib.linux-x86_64-3.4/_cffi_backend.cpython-34m.so

Successfully installed sounddevice CFFI
Cleaning up...

...which looks good... And finally:

$ python3 -m sounddevice
  0 HDA Intel HDMI: 0 (hw:0,3), ALSA (0 in, 8 out)
  1 HDA Intel HDMI: 1 (hw:0,7), ALSA (0 in, 8 out)
  2 HDA Intel HDMI: 2 (hw:0,8), ALSA (0 in, 8 out)
  3 HDA Intel PCH: ALC292 Analog (hw:1,0), ALSA (2 in, 2 out)
  4 hdmi, ALSA (0 in, 8 out)
  5 pulse, ALSA (32 in, 32 out)
* 6 default, ALSA (32 in, 32 out)

Sounds ok to me. :-)

@antonio-fiol Thanks for testing! I've merged #50 into master.

About your detached head: you were switching to the remote branch origin/issue-49, which you are normally not supposed to. You should have done this:

git checkout issue-49

Git (if you use a recent enough version) is intelligent enough to automatically create a local branch named issue-49 for you, that's tracking the remote branch origin/issue-49. Branches normally come in pairs, one local and one remote.

Also, you are not supposed to use make_dist.sh, that's just for me to create the releases.
To install a development version of the sounddevice module, follow the instructions in CONTRIBUTING.rst.