0

I'm trying to install python-chess package to Python 3.3 on Ubuntu 13.04. Here is a link to github (https://github.com/niklasf/python-chess), it is also possible to install it using pip.

When I install it to Python 2.7 (with pip or with setup.py from source code), everything works well, but when I try to install it to Python 3.3 with pip3 or running setup.py with python3, it seems to work well, but when I actually try to import it in python 3.3 interpreter, I get the following:

>>> import chess
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.3/dist-packages/python_chess-0.0.4-py3.3-linux-i686.egg/chess/__init__.py", line 30, in <module>
    from libchess import START_FEN
ImportError: /usr/lib/libboost_python-py27.so.1.53.0: undefined symbol: PyClass_Type
>>> 

It seems from this message, that the library is trying to use boost-python for Python 2.7, even though it was built and then installed with Python 3.3. I have boost-python package installed for both Python 2.7 and Python 3.3, so what I think I need is a way to let this library use /usr/lib/libboost_python-py33.so.1.53.0 file.

How can I achieve this? Or maybe my conclusion is wrong, and in that case, how do I really fix this problem?

Anton Guryanov
  • 12,109
  • 1
  • 15
  • 16

1 Answers1

2

python-chess uses some C++ code, that was compiled when you executed setup.py ; it found the Python 2.7 version of the boost library, and linked with it. Now you can't go back, you have to remove what you installed and recompile it again. This time, make sure it finds the right library. I guess you have a /usr/lib/libboost_python.so symlink to /usr/lib/libboost_python-py27.so.xxx, right ? You can temporarily change this symlink so it links with the right library, maybe.

EDIT: it works when linking statically and making sure /usr/lib/libboost_python.a points to /usr/lib/libboost_python-py33.a

mguijarr
  • 7,641
  • 6
  • 45
  • 72
  • But *.so is dynamically linked, so why should I recompile? I guess I'll need to permanently change this symlink, which is not that good, because it seems that this'll screw up Python 2.7 version of this library (it is ok for now, I need only Python 3.3 version, but I'd really like to implement a proper solution). I'll try what you've suggested and comment again with results. – Anton Guryanov Oct 08 '13 at 10:23
  • You are right except for one thing: I needed to change a symlink to a library `/usr/lib/libboost_python.a` to point to `/usr/lib/libboost_python-py33.a`, so that it statically links the correct version. Could you please edit this answer, so that it reflects this? – Anton Guryanov Oct 08 '13 at 10:31