Closed zsdonghao closed 7 years ago
Likely you used the python-config from python2, see the post here:
https://groups.google.com/a/kitt.ai/forum/#!topic/snowboy-discussion/3G0fobzUw-0
@chenguoguo Thank you so much let me have a try ~~
I guess the issue has been resolved? Closing this. Feel free to re-open it if it's not resolved.
Hey, I know this is a closed issue, but I am having the same problem. Can you explain how do I use the python-config for python3 ? I created a symbolic link, but not sure it is the right way, what exactly do I have to do?
@DarioBernardo you might have to use something like python3-config
emmm thanks for the reply, but what exactly that means? I never used python3-config before, what do I have to do exactly? Sorry for the noob question.
How did you set it up? Did you go to swig/Python3/
and type make
? When you type python3-config
in the command line, does that give you any errors?
I know this is an old thread but I provide you my solution in case this could be useful to someone with the same issue. Recently I tried to install snbowboy on my Ubuntu laptop with Python3 and I got the same importerror. My python configuration was ok and I had installed all the packages/modules required to run snowboy. Finally I decided to recompile snowboy for Python3. The error disappeared and now snowboy is working correctly. For what it's worth I had the same issue when I installed snowboy on my RPi on Raspbian stretch with Python3 and I fixed it the same manner so I assume this is not a hardware or system related issue.
By recompile do you mean make
under swig/Python3
?
Yes, this is what I did. I cloned the git repository and I did a make under swig/Python3. I thought this was ok to do that, let me know if I did something wrong. By the way there was an issue in the Makefile. The first line is "SWIG := swig" and when I ran a make it complained about swig not found. I did some checks and I noticed that when I installed swig3.0 (sudo apt-get swig3, the binary name is swig3.0 so I changed the line by "SWIG := swig3.0" and this time make finished correctly and I didn't have anymore the importerror when I executed snowboy.
Another way to correct the swig binary issue is to create a symbolic link /usr/bin/swig which points to /usr/bin/swig3.0. I don't know which one is the best.
OK thanks a lot. Yes people are supposed to make
under swig/Python3
because we don't provide pre-compiled libraries for Python3.
@zsdonghao It was actually due to the anaconda3 path, its mentioned in the makefile to be changed
use PYLIBS := -L/anaconda3/lib/python3.6/config-3.6m-darwin -lpython3.6m -ldl -framework CoreFoundation in your makefile
I had the python 2 vs 3 issue. It works on 2, but I get this error on 3. I cloned the SWIG repo. Did sh autogen.sh
then ./configure
so that I could run make
, but it requires PCRE. So, I downloaded and built that within the SWIG folder for convenience. ./configure still doesn't find PCRE. I'm also not seeing a Python3 folder in swig
so I must have done something wrong...
Yes, you need to fix the SWIG issue, then it will work. Probably you will have to modify the snowboy swig/Python Makefile too. I had to do the same, I downloaded the swig source code and compiled it locally to have it working. I hope it helps.
On Thu, Mar 1, 2018 at 12:41 AM, Jason Miller notifications@github.com wrote:
I had the python 2 vs 3 issue. It works on 2, but I get this error on 3. I cloned the SWIG repo. Did sh autogen.sh then ./configure so that I could run make, but it requires PCRE. So, I downloaded and built that within the SWIG folder for convenience. ./configure still doesn't find PCRE.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Kitt-AI/snowboy/issues/101#issuecomment-369434362, or mute the thread https://github.com/notifications/unsubscribe-auth/AJAq185AbwE2VmvCmXxwM3tE53t-IHa5ks5tZ0OogaJpZM4Lcbco .
@DarioBernardo Thanks. Yes some of my confusion was from using the version of SnowBoy compressed into an archive specifically for Raspberry Pi. That one doesn't have anything related to SWIG in it. But eventually I cloned the main repo which of course has SWIG.
I'm using the latest precompiled version for RPi on a 3B and I'm getting the same issue.
Can't run any demos from the unzipped project folder.
Traceback (most recent call last):
File "demo.py", line 1, in <module>
import snowboydecoder
File "/home/pi/rpi-arm-raspbian-8.0-1.1.1/snowboydecoder.py", line 5, in <module>
import snowboydetect
File "/home/pi/rpi-arm-raspbian-8.0-1.1.1/snowboydetect.py", line 28, in <module>
_snowboydetect = swig_import_helper()
File "/home/pi/rpi-arm-raspbian-8.0-1.1.1/snowboydetect.py", line 24, in swig_import_helper
_mod = imp.load_module('_snowboydetect', fp, pathname, description)
File "/home/pi/rpi-arm-raspbian-8.0-1.1.1/venv/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)
So there is a call to swig somewhere.
Incidentally:
$ which swig
/usr/bin/swig
$ swig -version
SWIG Version 3.0.12
Compiled with g++ [armv7l-unknown-linux-gnueabihf]
Configured options: +pcre
Can someone please help with this?
@Flowdeeps just a double check, you did make
under swig/Python3
right?
You might want to try it under a Python3 virtual environment.
There is no swig folder. It is the precompiled RPi zip from the how-to.
The folder contains the following:
demo2.py
demo.py
light.py
__pycache__
README.md
requirements.txt
resources
snowboydecoder.py
snowboydecoder.pyc
snowboydetect.py
_snowboydetect.so
version
The link was from here: http://docs.kitt.ai/snowboy/#downloads
I noticed that the how-to version differs from the main project readme version as well. https://s3-us-west-2.amazonaws.com/snowboy/snowboy-releases/rpi-arm-raspbian-8.0-1.1.1.tar.bz2 https://s3-us-west-2.amazonaws.com/snowboy/snowboy-releases/rpi-arm-raspbian-8.0-1.3.0.tar.bz2
Neither work.
@Flowdeeps If you are using the pre-built libraries, it's possible that it didn't fit your particular platform.
Instead, check out this repository and follow the README to build a library for yourself.
Hi, I'm still having trouble with this issue. I'm using python3 on mac os I have tried 2 methods and both give the same error.
Both of these give:
ImportError: dynamic module does not define module export function (PyInit__snowboydetect)
Earlier in this thread you advised people to do make
in swig/Python3
, sorry for the stupid question but where can I find this swig/Python3
directory?
I got here from picovoice, so running python 3.6. Up until this point I had followed the following directions:
cd snowboy/
sudo apt-get install python-pyaudio python3-pyaudio sox
pip install pyaudio
wget http://downloads.sourceforge.net/swig/swig-3.0.10.tar.gz
sudo apt-get install libpcre3 libpcre3-dev
tar -zxvf swig-3.0.10.tar.gz
cd swig-3.0.10/
./configure --prefix=/usr --without-clisp --without-maximum-compile-warnings
make
make install
sudo make install
sudo install -v -m755 -d /usr/share/doc/swig-3.0.10
sudo cp -v -R Doc/* /usr/share/doc/swig-3.0.10
sudo apt-get install libatlas-base-dev
cd ..
Then I got the ImportError: dynamic module does not define init function (PyInit__snowboydetect)
error trying to run the demo.
To fix this error:
cd snowboy/swig/Python3
vim Makefile
# and add before the all rule add: CXXFLAGS += -fno-lto
make
Then edit a python file:
cd snowboy/examples/Python3
vim snowboydecoder.py
and as in #316 comment out the line from . import snowboydetect
and add the lines:
from os.path import dirname
curpath = dirname(__file__)
import imp
snowboydetect = imp.load_source('snowboydetect', curpath+'/snowboydetect.py')
Then I was able to do the following while in snowboy/examples/Python3
:
>>> import snowboydecoder
>>> def detected_callback():
... print("hotword detected")
...
>>> detector = snowboydecoder.HotwordDetector("../../resources/models/snowboy.umdl", sensitivity=0.5, audio_gain=1)
Since I don't have a microphone:
cd snowboy/examples/Python3
python demo3.py ../../resources/snowboy.wav ../../resources/models/snowboy.umdl
I am using Macbook, snowboy works well with Python2. But I get error with Python3 on Quick Start for Python Demo.
Anyone have idea about that?