Skip to content
This repository was archived by the owner on Jun 9, 2022. It is now read-only.

Conversation

@jschueller
Copy link
Contributor

@jschueller jschueller commented Dec 17, 2018

Python3 uses absolute imports, so "from sphinxbase import *" does nothing as it thinks you want to import again the current module thats being imported (the sphinxbase directory), so it does not import the swig module (the sphinxbase.py / _sphinbase.so files).

You can try this for yourself on this example:

$ mkdir foo
$ echo "from foo import *" > foo/__init__.py
$ echo "print('import ok')" > foo/foo.py
$ python2 -c "import foo"
import ok
$ python3 -c "import foo"
$ <== [no output, foo.py is not imported]

now use a relative import:

$ echo "from .foo import *" > foo/__init__.py
$ python2 -c "import foo"
import ok
$ python3 -c "import foo"
import ok

I successfully fixed the import of sphinxbase and pocketsphinx using this fix, tested on python2 & python3 using this docker script:

FROM ubuntu:bionic
MAINTAINER jschueller
ENV MAKEFLAGS "-j4"
ENV TERM dumb
WORKDIR /tmp
RUN apt-get -y update
RUN apt-get install -y git swig python-dev python3-dev liblapack-dev sudo bison autoconf automake libtool make
RUN useradd -m -d /home/ubuntu -u 1000 -U -G users,tty -s /bin/bash ubuntu
RUN echo 'ubuntu ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
USER ubuntu

RUN git clone --depth 1 https://github.com/cmusphinx/sphinxbase.git && cd sphinxbase && sed -i "s|from sphinxbase|from .sphinxbase|g" swig/python/__init__.py && autoreconf -i && mkdir py2 && cd py2 && ../configure --prefix=/home/ubuntu/.local && make && make install && cd .. && mkdir py3 && cd py3 && PYTHON=/usr/bin/python3 ../configure --prefix=/home/ubuntu/.local && make && make install
RUN python2 -c "from sphinxbase import LogMath; print(LogMath().exp(3))"
RUN python3 -c "from sphinxbase import LogMath; print(LogMath().exp(3))"

RUN git clone --depth 1 https://github.com/cmusphinx/pocketsphinx.git && cd pocketsphinx && sed -i "s|from pocketsphinx|from .pocketsphinx|g" swig/python/__init__.py && autoreconf -i && mkdir py2 && cd py2 &&  ../configure --with-sphinxbase=/home/ubuntu/.local/ --prefix=/home/ubuntu/.local && make SWIG_FLAGS="-I/home/ubuntu/.local/share/sphinxbase/swig" && make install && cd .. && mkdir py3 && cd py3 && PYTHON=/usr/bin/python3 ../configure --with-sphinxbase=/home/ubuntu/.local/ --prefix=/home/ubuntu/.local && make SWIG_FLAGS="-I/home/ubuntu/.local/share/sphinxbase/swig" && make install
RUN python2 -c "from pocketsphinx import Decoder; config = Decoder.default_config()"
RUN python3 -c "from pocketsphinx import Decoder; config = Decoder.default_config()"

jschueller added a commit to jschueller/pocketsphinx that referenced this pull request Dec 17, 2018
@jschueller
Copy link
Contributor Author

what do you say @nshmyrev ? should this patch and its pocketsphinx counterpart go in now ?

@nshmyrev
Copy link
Contributor

nshmyrev commented Mar 6, 2019

Hello Julien. I'm sorry, I kinda lost it, I'll look tomorrow.

@jschueller
Copy link
Contributor Author

Cool, thanks

@nshmyrev
Copy link
Contributor

Gentle reminder for myself hehe

@nshmyrev nshmyrev merged commit 87a3e90 into cmusphinx:master Mar 18, 2019
@nshmyrev
Copy link
Contributor

And thank you!

@jschueller jschueller deleted the patch-1 branch March 18, 2019 14:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants