Kitt-AI / snowboy

Future versions with model training module will be maintained through a forked version here: https://github.com/seasalt-ai/snowboy
Other
3.11k stars 1.01k forks source link

Python 3.4 throws swig errors #35

Closed sciguy14 closed 7 years ago

sciguy14 commented 8 years ago

Got it built for the pi, inside a venv. Super cool! However, although I'm able to run the demo with python 2.7, it fails when I try to run it using Python 3.4 (the default inside my virtual env).

Traceback (most recent call last):
  File "demo.py", line 1, in <module>
    import snowboydecoder
  File "/home/pi/jarvis/snowboy/examples/Python/snowboydecoder.py", line 5, in <module>
    import snowboydetect
  File "/home/pi/jarvis/snowboy/examples/Python/snowboydetect.py", line 28, in <module>
    _snowboydetect = swig_import_helper()
  File "/home/pi/jarvis/snowboy/examples/Python/snowboydetect.py", line 24, in swig_import_helper
    _mod = imp.load_module('_snowboydetect', fp, pathname, description)
  File "/usr/lib/python3.4/imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
ImportError: dynamic module does not define init function (PyInit__snowboydetect)

I followed these instructions regarding getting it compiled: https://github.com/Kitt-AI/snowboy/issues/17

chenguoguo commented 8 years ago

Hi, looks like it's related to swig. We have't tested Python3 yet. I'll have a try to see if I can update my Python without breaking my existing stuff :-)

chenguoguo commented 8 years ago

I'll leave this up for a while. I haven't figured out the best way to pass data from Python to C++ using swig without changing a lot of stuff. We are using string in Python2.x but the string object in Python3.* now holds unicode instead of bytes.

sciguy14 commented 8 years ago

Understood. Figured that was the cause, just wanted to bring it to your attention. In the meanwhile, I'm happily using Python2.7 with Snowboy and it's working great. Every year or so, I say to myself, "Maybe it's time for me to give Python3 another shot", and then I do it, and everything breaks, and I find myself back in the warm embrace of Python2.x again.

On Mon, Jul 25, 2016 at 9:34 AM, Guoguo Chen notifications@github.com wrote:

I'll leave this up for a while. I haven't figured out the best way to pass data from Python to C++ using swig without changing a lot of stuff. We are using string in Python2.x but the string object in Python3.* now holds unicode instead of bytes.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Kitt-AI/snowboy/issues/35#issuecomment-235007677, or mute the thread https://github.com/notifications/unsubscribe-auth/AArT78rGIFfHvT5_cqFTfhO6-g5NRaGdks5qZOV4gaJpZM4JTTau .

Jeremy E. Blum Blum Idea Labs LLC. www.jeremyblum.com jeremy@jeremyblum.com

Check out my book: Exploring Arduino http://www.exploringarduino.com

chenguoguo commented 8 years ago

@sciguy14 could you check out the devel branch and give it a shot with your python3? you will have to compile the library with your python3 dependencies using this makefile. please also make sure you use swig 3.0.10. Let me know if it works.

ghost commented 8 years ago

getting the same error, root@raspberrypi:~/AlexaPi# python start.py Alexa.pmdl Traceback (most recent call last): File "start.py", line 2, in import main File "/root/AlexaPi/main.py", line 24, in import snowboydecoder File "/root/AlexaPi/snowboydecoder.py", line 6, in import snowboydetect File "/root/AlexaPi/snowboydetect.py", line 28, in _snowboydetect = swig_import_helper() File "/root/AlexaPi/snowboydetect.py", line 20, in swig_import_helper import _snowboydetect ImportError: No module named _snowboydetect

been trying to do https://github.com/flooie/AlexaPi/ and this bit has me stumped, this is on a pi2 with the latest rasbian version (full not light)

I thought perhaps i need to install snowboy, so checked the site out, downloaded the tar.bz2 (first time seeing that type of file) extracted it tar xf rpi-arm-raspbian-8.0-1.0.4.tar.bz2 cd into it read the readme....man thats one confusing readme sudo apt-get install swig3.0 python-pyaudio python3-pyaudio sox
yep pip install pyaudio yep sudo apt-get install libatlas-base-dev yep quote "

Compile a Python Wrapper

cd swig/Python
make

" no such folder as swig....... and there im stuck

the rec t.wav command works though...not sure if thats relevent but its hearing my mic after i followed the steps to set it up.....just cant get the main program to use the snowboydetect.py

chenguoguo commented 8 years ago

oh if you want to compile, you have to checkout this repository https://github.com/Kitt-AI/snowboy instead of downloading the pre-compiled tarballs.

ghost commented 8 years ago

curious to see if anyone had any luck getting this going on the devel branch?

Darkein commented 8 years ago

Tried with the devel branch, unfortunately got the same result.

I'm using ubuntu 16.04 x64 whose don't have swig 3.0.10 in it's repo so i recompiled it. I tried to modify the makefile to use python3-config and added -py3 parameter to swig, without success.

I don't want to going back to python 2 :(

chenguoguo commented 8 years ago

The problem might be Ubuntu 16.04. We've only compiled Snowboy for Ubuntu 14.04 so far, so the library was only tested on 14.04 and I'm not too sure if it works on 16.04. If someone has tested it on 16.04, please let us know.

chenguoguo commented 8 years ago

Could someone tell if if the current devel branch works on Python3? I just fixed an issue on Ubuntu 16.04 (g++ version related) so it should works on Ubuntu 16.04 now. If the Python3 is still not working, let's try to fix it.

tadly commented 8 years ago

I'd really like to test the devel branch but building this thing on archlinux is a pain (well atlas is a pain on arch) and on debian I'm kinda struggling to get it to static link the atlas stuff.

Mind telling me how you guys create the builds with atlas being statically linked?

chenguoguo commented 8 years ago

@tadly we build the Python module using swig through this Makefile. The default does not link ATLAS statically.

tadly commented 8 years ago

@chenguoguo yeah, I know that already and did that as well. :) However I'm unable to include Atlas in the resulting build as mentioned in this inline-comment

chenguoguo commented 8 years ago

I see, you were trying to statically link to atlas on debian. When you install atlas on debian, I think both the .a and the .so libraries are installed. Then instead of using LDLIBS := -lm -ldl -lf77blas -lcblas -llapack_atlas -latlas, you use something like LDLIBS := -lm -ldl /usr/lib/atlas-base/libf77blas.a /usr/lib/atlas-base/libcblas.a /usr/lib/atlas-base/liblapack_atlas.a /usr/lib/atlas-base/liblatlas.a

tadly commented 8 years ago

hm.. well that was way to easy. Spent over an hour googlen on how to force use static libs while building instead of shared ones and all I found was -Wl,-strict which didn't quite workout for me.

Anyway, thank you very much. Building it works now and I'll do some testing tomorrow even though v1.1.0 added official python3 support which renders this issue kinda useless by now :) While on that topic, you provide precompiled binaries already. Mind adding one for 16.04 built with python3?

I can build it myself now (again, thanks for helping) but it might be generally useful for others :)

chenguoguo commented 8 years ago

you should be able to use the 14.04 snowboy library and build it on 16.04 by yourself. we haven't thoroughly tested python3 so expect issues :-)

nyboer commented 8 years ago

Working with Python 2.79 on C.H.I.P. Installed all the dependencies. Cloned the git, cd to snowboy/swig/Python and tried make. Swig threw an error. I had to change the Makefile (right near the top) to SWIG := swig3.0

For search-ability, here's the actual errors.

swig -I../../ -c++ -python -o snowboy-detect-swig.cc snowboy-detect-swig.i
make: swig: Command not found
Makefile:44: recipe for target 'snowboy-detect-swig.cc' failed
make: *** [snowboy-detect-swig.cc] Error 127
chenguoguo commented 8 years ago

@nyboer hi yes you will have to link swig to your installed version (we are using swig 3.0.10).

chenguoguo commented 7 years ago

I believe the issue has been resolved, so closing this. Critical points are:

  1. Make sure swig 3.0.10 is used in the Makefile
  2. Make sure python-config in the Makefile is linked to your python3 instead of python2
ppirrip commented 6 years ago

This might be related. Has anything encountered this Python3 error: self.detector = snowboydetect.SnowboyDetect(common_resource, model) File "/home/ppirrip/.local/lib/python3.5/site-packages/snowboy/snowboydetect.py", line 109, in init this = _snowboydetect.new_SnowboyDetect(resource_filename, model_str) TypeError: in method 'new_SnowboyDetect', argument 1 of type 'std::string const &'

This is from the latest Raspbian and dev branch.

SWIG Version 3.0.10 Compiled with g++ [armv7l-unknown-linux-gnueabihf] Configured options: +pcre

Python2 works perfect. I try to do a work-around from python side (force the string to ascii etc.) but doesn't seem to work.

chenguoguo commented 6 years ago

When you were compiling for Python3, did you make sure the python-config you used was for Python3 instead of Python2?

ppirrip commented 6 years ago

Where is the python-config? I can't locate it anywhere. I use the make in the dir snowboy/swig/Python3

Just for sanity check, the _snowboydetect.so is different for python2 and python3

chenguoguo commented 6 years ago

It's is different.

Finding python-config is really a python question instead of Snowboy. Please try some searches on Google.