LibXtract icon indicating copy to clipboard operation
LibXtract copied to clipboard

Python bindings in 2019

Open CedricVanhaverbeke opened this issue 5 years ago • 2 comments

Hi

I just successfully executed the command make swig and I wanted to give my feedback on how I did it.

  1. First things first, you should be able to execute make install in the root of the project. So before anything else, do this. This should install LibXtract to /usr/local. If that didn't work execute following command: make install PREFIX=/usr/local

  2. Next up, let's install swig: In Ubuntu (or WSL for that matter). This is done by these commands:

git clone https://github.com/swig/swig.git

cd swig
sudo apt-get install automake
./autogen.sh
./configure
sudo apt-get install bison flex
make
sudo make install

You can choose where you want to clone the project to. I just did it in the folder where I want to use LibXtract.

  1. when you'd execute 'make swig' in the root folder of the project you would probably get following error:
xtract_wrap.c:154:11: fatal error: Python.h: No such file or directory
 # include <Python.h>
           ^~~~~~~~~~
compilation terminated.

This is because the devtools of Python aren't installed or your OS cannot find them. Before installing the devtools, check your Python version with python --version. You should install the right devtools for your version.

sudo apt-get install python<version here>-devtools

An overview of all the commands in different OS's: https://icetutor.com/question/fatal-error-python-h-no-such-file-or-directory/

I still had a problem. Even though I installed the devtools, I couldn't import Python.h . I use anaconda and that was the problem.

Open swig/Makefile in an editor of your choice and change the value of the -I flag to the location of your devtools. In anaconda you'd get something like /home/youruser/anaconda3/include/python3.6m.

So, on line 22 and 23 change these values:

	@swig -I/path/to/devtools -python $(NAME).i
	@$(CC) $(CFLAGS) $(NAME)_wrap.c -o $(NAME)_wrap.o -I$(INCLUDEPY) -I/path/to/devtools

Also, the provided test file is outdated. sei-nicolas created an alternative one in issue #93 (find it here)

I hope this helps! cheers

CedricVanhaverbeke avatar Oct 24 '19 13:10 CedricVanhaverbeke

Thanks! In 2021, I had to install sudo apt install python3-dev, and edit swig/Makefile to remove -framework Accelerate. I'm not sure what this is.

I'm not sure how to actually install the python library, though..

yaxu avatar Jul 07 '21 12:07 yaxu