Last Updated: December 01, 2017
· smmorneau

Installing libtorrent on Linux

Libtorrent by Rasterbar is a C++ BitTorrent library with Python bindings.

Installing libtorrent for Python requires only one shell command

sudo apt-get install python-libtorrent

but building from the source (if you want to make any modifications) requires a little more work.

Apt-Get is the easiest way to install all the dependencies.

sudo apt-get build-dep python-libtorrent

Grab the latest released tarball from here and build.

tar -zxvf libtorrent-rasterbar-0.16.9.tar.gz
cd libtorrent-rasterbar-0.16.9
./configure --enable-python-binding
sudo make install

You may see the following output:

Libraries have been installed in:

Add this directory to your path. (You may consider adding it to your ~/.profile.)

export LD_LIBRARY_PATH=/usr/local/lib/

Now build the Python bindings.

cd bindings/python
python build
sudo python install

Then try importing the library in Python.

>>> import libtorrent

If it imports libtorrent without complaints, you are DONE!

If Python can't open the shared object file, it isn't looking in the right place.

>>> import libtorrent
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot open shared object file: No such file or directory

You can search for the shared object file

sudo updatedb

which should output the location.


Add the enclosing directory to your path

export LD_LIBRARY_PATH=/<path_to_directory>/

and try importing libtorrent again.

Say Thanks

1 Response
Add your response

260714 100000099962213 1419786796 n normal

Cool! I've searching a tutorial like this for days!

over 1 year ago ·
Filed Under