nnarain / gameboycore-python

Python Bindings for GameboyCore
MIT License
5 stars 2 forks source link

Issues when installing in Debian / Docker container #11

Closed max-vogler closed 6 years ago

max-vogler commented 6 years ago

Hey @nnarain!

I would love to use gameboycore-python for an AI project similar to MarI/O - Machine Learning for Video Games. For this purpose, I'm trying to install it in Debian (running in a Docker container) with Python 3.6.

When installing your library using pip install gameboycore-python, I'm getting the error:

Traceback (most recent call last):
  File "mario.py", line 1, in <module>
    import gameboycore
ImportError: dynamic module does not define module export function (PyInit_gameboycore)

After successful manual compilation, when trying to run the demo you provided in https://github.com/nnarain/gameboycore-python/issues/8#issuecomment-269588554, I'm always getting the error:

Traceback (most recent call last):
  File "mario.py", line 1, in <module>
    import gameboycore
ImportError: /app/gameboycore-python/gameboycore.cpython-36m-x86_64-linux-gnu.so: undefined symbol: _ZTIN5boost6python15instance_holderE

For reference, my Dockerfile is this (I know that I'm running the installation code multiple times, that's part of the debugging):

# Python 3.6 is not yet available in Debian Stretch (9)
FROM debian:testing
WORKDIR /app

RUN apt-get update -qq && \
    apt-get install -y make git cmake gcc g++ python3.6-dev python3.6 wget libdpkg-perl libboost-python-dev && \
    wget -q -O-  https://bootstrap.pypa.io/get-pip.py | python3.6

WORKDIR /usr/lib
RUN wget -qq https://sourceforge.net/projects/boost/files/boost/1.61.0/boost_1_61_0.tar.gz && \
    tar -xzf boost_*.tar.gz && \
    rm boost_*.tar.gz

ENV BOOST_ROOT=/usr/lib/boost_1_61_0
ENV CPLUS_INCLUDE_PATH="$CPLUS_INCLUDE_PATH:/usr/include/python3.6/"
WORKDIR $BOOST_ROOT
RUN echo "using python : 3.6 ;" > user-config.jam
RUN ./bootstrap.sh
RUN ./b2 --with-system --with-python python-debugging=off threading=multi variant=release link=static stage
RUN ./b2 --with-system --with-python python-debugging=off threading=multi variant=release link=static install

WORKDIR /app/gameboycore-python
ADD gameboycore-python .

ENV PYTHON_ROOT=/usr/local/lib/python3.6
WORKDIR /app/gameboycore-python/src/gameboycore/build
RUN cmake .. -DBUILD_EXAMPLE="OFF" && make

WORKDIR /app/gameboycore-python
RUN python3.6 setup.py build
RUN pip install -e .

WORKDIR /app
ADD . .
CMD ["python3.6", "-u", "mario.py"]
nnarain commented 6 years ago

Hey @max-vogler !

Small update.

With regards to the first issue: ImportError: dynamic module does not define module export function (PyInit_gameboycore)

pip can't install .egg files. And it seems pypi will not accept .whl files with the linux_x86_64 tag. So the solution is to install using easy_install.

This should do the trick:

easy_install gameboycore

So you should not have to install from source.

Still digging on the second issue: ImportError: /app/gameboycore-python/gameboycore.cpython-36m-x86_64-linux-gnu.so: undefined symbol: _ZTIN5boost6python15instance_holderE

max-vogler commented 6 years ago

Thanks for your feedback! Using easy_install gameboycore works for the installation, but still yields the undefined symbol error.

I suspect it's some sort of linking error? Is it possible to be flexible about the used Boost version? This could simplify installation to something around 3 steps:

apt-get update
apt-get install -y python3-dev python3-pip libboost-python
easy_install gameboycore
nnarain commented 6 years ago

Updated the docs a bit but forgot to update the issue, sorry.

If you build from source and then add the /path/to/boost/stage/lib/ directory to the LD_LIBRARAY_PATH environment variable you should be up and running.

nnarain commented 6 years ago

What I can do is build the extension against the version of boost in the apt repo. Will simplify installation.

max-vogler commented 6 years ago

It works when adding the path to LD_LIBRARY_PATH, thanks! Here is a working Dockerfile:

FROM debian:testing

RUN apt-get update -qq && \
    apt-get install -y make git cmake gcc g++ python3.6-dev python3.6 wget libdpkg-perl && \
    wget -q -O-  https://bootstrap.pypa.io/get-pip.py | python3.6
ENV CPLUS_INCLUDE_PATH="/usr/include/python3.6"

WORKDIR /opt
RUN wget -qq https://sourceforge.net/projects/boost/files/boost/1.60.0/boost_1_60_0.tar.gz && \
    tar -xzf boost_*.tar.gz && \
    rm boost_*.tar.gz
ENV BOOST_ROOT=/opt/boost_1_60_0

WORKDIR $BOOST_ROOT
RUN echo "using python : 3.6 ;" > $HOME/user-config.jam
RUN ./bootstrap.sh
RUN ./b2 --with-system --with-python python-debugging=off threading=multi variant=release link=shared stage
ENV LD_LIBRARY_PATH="$BOOST_ROOT/stage/lib"

RUN easy_install gameboycore