Setting up your development environment

This page contains instructions on how to setup your development environment to run Tribler from source.

Windows

This section contains information about setting up a Tribler development environment on Windows. Unlike Linux based systems where installing third-party libraries is often a single apt-get command, installing and configuring the necessary libraries requires more attention on Windows. Moreover, the Windows environment has different file stuctures. For instance, where Linux is working extensively with .so (shared object) files, Windows uses DLL files.

Introduction

In this guide, all required dependencies of Tribler will be explained. It presents how to install these dependencies. Some dependencies have to be built from source whereas other dependencies can be installed using a .msi installer. The guide targets Windows 10, 64-bit systems, however, it is probably not very hard to install 32-bit packages.

First, Python 2.7 should be installed. If you already have a Python version installed, please check whether this version is 64 bit before proceeding.

python -c "import struct;print( 8 * struct.calcsize('P'))"

This outputs whether your current installation is 32 or 64 bit.

Python can be downloaded from the official Python website. You should download the Windows x86-64 MSI Installer which is an executable. During the setup, remember to install pip/setuptools and to add Python to the PATH variable to access Python from the command line. The option to add Python to the PATH variable is unchecked by default! You can verify whether Python is installed correctly by typing python in the command line. Also check whether pip is working by typing pip in the command line. If they are not working, check whether the PATH variables are correctly set.

If you did not change the default installation location, Python should be located at C:\\Python27\\. The third-party libraries are located in C:\\Python27\\Lib\\site-packages. If you forgot to add Python to your PATH during the setup, you should need to add the C:\\Python27\\ and C:\\Python27\\Scripts directories to your PATH variable.

In order to compile some of the dependencies of Tribler, you will need Visual Studio 2015 which can be downloaded from here. You should select the community edition. Visual Studio ships with a command line interface that can be used for building some of the Python packages. Moreover, it provides a nice IDE which can be used to work on Python projects. After installation of Visual Studio, you should install the Visual C++ tools. This can be done from within Visual Studio by creating a new Visual C++ project. Visual Studio then gives an option to install the Visual C++ developer tools.

In case importing one of the modules fail due to a DLL error, you can inspect if there are files missing by opening it with Dependency Walker. It should show missing dependencies. In our case, we were missing MSVCR100.DLL which belongs to the Microsoft Visual C++ 2010 SP1 Redistributable Package (x64). This package can be downloaded from the Microsoft website. One other DLL that was missing was MSVCR110.DLL, which belongs to the Visual C++ Redistributable for Visual Studio 2012 Update 4. After installing these two pakets, there should be no more import errors.

M2Crypto

The first package to be installed is M2Crypto which can be installed using pip (the M2Crypto binary is precompiled):

pip install --egg M2CryptoWin64 # use M2CryptoWin32 for the 32-bit version of M2Crypto
python -c "import M2Crypto" # test whether M2Crypto can be successfully imported

If the second statement does not raise an error, M2Crypto is successfully installed.

wxPython

The graphical interface of Tribler is built using wxPython. wxPython can be installed by using the official win64 installer for Python 2.7 from Sourceforge. At the time of writing, wx3 is not supported yet so you should install wx2.8 (make sure to install the unicode version). You can test whether wx can be successfully imported by running:

python -c "import wx"

This statement should proceed without error.

pyWin32 Tools

In order to access some of the Windows API functions, pywin32 should be installed. The pywin32 installer can be downloaded from Sourceforge and make sure to select the amd64 version and the version compatible with Python 2.7.

## apsw The apsw (Another Python SQLite Wrapper) installer can be downloaded from GitHub. Again, make sure to select the amd64 version that is compatible with Python 2.7. You can test whether it is installed correctly by running:

python -c "import apsw"

libtorrent

This package should be compiled from source. First, install Boost which can be downloaded from SourceForge. Make sure to select the latest version and choose the version is compatible with your version of Visual C++ tools (probably msvc-14).

After installation, you should set an environment variable to let libtorrent know where Boost can be found. You can do this by going to Control Panel > System > Advanced > Environment Variables (more information about setting environment variables can be found here). Now add a variable named BOOST_ROOT and with the value of your Boost location. The default installation location for the Boost libraries is C:\\local\\boost_<BOOST VERSION> where <BOOST VERSION> indicates the installed Boost version.

Next, you should build Boost.build. You can do this by opening the Visual Studio command prompt and navigating to your Boost libraries. Navigate to tools\\build and execute bootstrap.bat. This will create the b2.exe file. In order to invoke b2 from anywhere in your command line, you should add the Boost directory to your user PATH environment variable. After modifying your PATH, you should reopen your command prompt.

Now, download the libtorrent source code from GitHub and extract it. It is advised to compile version 1.0.8. Note that you if you have a 32-bit system, you can download the .msi installer so you do not have to compile libtorrent yourself. Open the Developer Command Prompt shipped with Visual Studio (not the regular command prompt) and navigate to the location where you extracted the libtorrent source. In the directory where the libtorrent source code is located, navigate to bindings\\python and build libtorrent by executing the following command (this takes a while so make sure to grab a coffee while waiting):

b2 boost=source libtorrent-link=static address-model=64

This command will build a static libtorrent 64-bit debug binary. You can also build a release binary by appending release to the command given above. After the build has been completed, the resulting libtorrent.pyd can be found in LIBTORRENT_SOURCE\\bindings\\python\\bin\\msvc-14\\debug\\address-model-64\\boost-source\\link-static\\ where LIBTORRENT_SOURCE indicates the directory with the libtorrent source files. Copy libtorrent.pyd to your site-packages location (the default location is C:\\Python27\\Lib\\site-packages) and test libtorrent by executing:

python -c "import libtorrent"

libsodium

Libsodium can be download as precompiled binary from their website. Download the latest version, built with msvc. Extract the archive to any location on your machine. Next, you should add the location of the dynamic library to your PATH variables (either as system variable or as user variable). These library files can be found in LIBSODIUM_ROOT\\x64\\Release\\v140\\dynamic\\ where LIBSODIUM_ROOT is the location of your extracted libsodium files. After modifying your PATH, you should reopen your command prompt. You test whether Python is able to load libsodium.dll by executing:

python -c "import ctypes; ctypes.cdll.LoadLibrary('libsodium')"

LevelDB

The next dependency to be installed is levelDB. LevelDB is a fast key-value storage written by Google. LevelDB itself is written in C++ but there are several Python wrappers available. In this guide, you will compile leveldb from source. First, download the source code from GitHub (either clone the repository or download the source code as zip). The readme on this repo contains some basic instructions on how to compile leveldb.

Next, open the levedb_ext.sln file in Visual Studio. This guide is based on the x64 release configuration. If you want to build a 32-bit leveldb project, change the configuration to win32 release.

You should edit the file paths of the include directories and the linker directories. These can be edited by right clicking on the project and selecting properties. You will need to update additional include directories (under C/C++ -> general) to point to your Python include directory (often located in C:\\Python27\\include). This is needed for the compilation of the Python bindings. Also, make sure that the following preprocessor definitions (found under C/C++ -> preprocessor) are defined: WIN32 and LEVELDB_PLATFORM_WINDOWS.

Next, additional library directories should be adjusted, found under Linker -> General. You should add the directory where your Python libraries are residing, often in C:\\Python27\\libs.

Compile by pressing the build leveldb_ext in the build menu. If any errors are showing up during compilation, please refer to the Visual Studio log file and check what’s going wrong. Often, this should be a missing include/linker directory. If compilation is successful, a leveldb_ext.pyd file should have been created in the project directory. Copy this file to your site-packages location and rename it to leveldb.pyd so Python is able to find it. You can test whether your binary is working by using the following command which should execute without any errors:

python -c "import leveldb"

VLC

To install VLC, you can download the official installer from the VideoLAN website. Make sure to install the 64-bit version of VLC.

Additional Packages

There are some additional packages which should be installed. They can easily be installed using pip:

pip install cherrypy chardet configobj cryptography decorator feedparser netifaces pillow twisted

Running Tribler

You should now be able to run Tribler from command line. Grab a copy of the Tribler source code and navigate in a command line interface to the source code directory. Start Tribler by running:

python Tribler\Main\tribler.py

You might get errors about imports in the Tribler module. To fix this, you should add the location where the Tribler directory is located to the PYTHONPATH user environment variables. Information about changing environment variables can be found here.

If there are any problems with the guide above, please feel free to fix any errors or create an issue so we can look into it.

OS X

This section contains information about setting up a Tribler development environment on OS X. Unlike Linux based systems where installing third-party libraries is often a single apt-get command, installing and configuring the necessary libraries requires more attention on OS X. This guide has been tested with OS X 10.10.5 (Yosemite) but should also work for OS X 10.11 (El Capitan).

Note that the guide below assumes that Python is installed in the default location of Python (shipped with OS X). This location is normally in /Library/Python/2.7. Writing to this location requires root acccess when using easy_install or pip. To avoid root commands, you can install Python in a virtualenv. More information about setting up Python in a virtualenv can be found here.

Introduction

Compilation of C/C++ libraries should be performed using Clang which is part of the Xcode Command Line Tools. The Python version shipped with OS X can be used and this guide has been tested using Python 2.7. The current installed version and binary of Python can be found by executing:

python --version # gets the python version
which python # prints the path of the Python executable

Note that the default location of third-party Python libraries (for example, installed with pip) can be found in /Library/Python/2.7/site-packages.

Many packages can be installed by using the popular brew and pip executables. Brew and pip can be installed by using:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
sudo easy_install pip

This should be done after accepting the Xcode license so open Xcode at least once before installing Brew.

Xcode Tools

The installation of Xcode is required in order to compile some C/C++ libraries. Xcode is an IDE developed by Apple and can be downloaded for free from the Mac App Store. After installation, the Command Line Tools should be installed by executing:

xcode-select --install

WxPython

WxPython is the Graphical User Interface manager and an installer can be downloaded from their website. Note that at this point, Wx 2.8 should still be used but support for 2.8 will be dropped soon and the Wx 2.8 library should be replaced by Wx 3.0. You probably need the Cocoa version of Wx.

Note: there is a bug on OS X 10.11 (El Capitan) where the installer gives an error that there is no software available to install. A workaround for this is to install the required files manually. This can be done by opening the .pkg file. First, you should run the preflight.sh script as root to clean up any old installation of wx. Next, unzip the wxPython3.0-osx-cocoa-py2.7.pax.gz file. This will create a usr directory which should be copied to /usr on the system. Note that you need root permissions to write to this directory (you can open a finder window with the needed permissions by running sudo open /usr in terminal). To link wx so Python can find it, you should run the postflight.sh as root.

M2Crypto

To install M2Crypto, Openssl has to be installed first. The shipped version of openssl by Apple gives errors when compiling M2Crypto so a self-compiled version should be used. Start by downloading openssl 0.98 from here, extract it and install it:

./config --prefix=/usr/local
make && make test
sudo make install
openssl version # this should be 0.98

Also Swig 3.0.4 is required for the compilation of the M2Crypto library. The easiest way to install it, it to download Swig 3.0.4 from source here and compile it using:

./configure
make
sudo make install

Note: if you get an error about a missing PCRE library, install it with brew using brew install pcre.

Now we can install M2Crypto. First download the source (version 0.22.3 is confirmed to work on El Capitan and Yosemite) and install it:

python setup.py build build_ext --openssl=/usr/local
sudo python setup.py install build_ext --openssl=/usr/local

Reopen your terminal window and test it out by executing:

python -c "import M2Crypto"

Apsw

Apsw can be installed by brew but this does not seem to work to compile the last version (the Clang compiler uses the sqlite.h include shipped with Xcode which is outdated). Instead, the source should be downloaded from their Github repository (make sure to download a release version) and compiled using:

sudo python setup.py fetch --all build --enable-all-extensions install test
python -c "import apsw" # verify whether apsw is successfully installed

Libtorrent

An essential dependency of Tribler is libtorrent. libtorrent is dependent on Boost, a set of C++ libraries. Boost can be installed with the following command:

brew install boost
brew install boost-python

Now we can install libtorrent:

brew install libtorrent-rasterbar --with-python

After the installation, we should add a pointer to the site-packages of Python so it can find the new libtorrent library using the following command:

sudo echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Library/Python/2.7/site-packages/homebrew.pth

This command basically adds another location for the Python site-packages (the location where libtorrent-rasterbar is installed). This command should be executed since the location where brew installs the Python packages is not in sys.path. You can test whether libtorrent is correctly installed by executing:

python
>>> import libtorrent

Other Packages

There are a bunch of other packages that can easily be installed using pip and brew:

brew install homebrew/python/pillow gmp mpfr libmpc libsodium
pip install --user cherrypy cffi chardet configobj cryptography decorator feedparser gmpy2 idna leveldb netifaces numpy pillow pyasn1 pycparser twisted service_identity

If you encounter any error during the installation of Pillow, make sure that libjpeg and zlib are installed. They can be installed using:

brew tap homebrew/dupes
brew install libjpeg zlib
brew link --force zlib

Tribler should now be able to startup without warnings by executing this command in the Tribler root directory:

./tribler.sh

If there are any missing packages, they can often be installed by one pip or brew command. If there are any problems with the guide above, please feel free to fix any errors or create an issue so we can look into it.

System Integrity Protection on El Capitan

The new security system in place in El Capitan can prevent libsodium.dylib from being dynamically linked into Tribler when running Python. If this library cannot be loaded, it gives an error that libsodium could not be found. This is because the DYLD_LIBRARY_PATH cannot be set when Python starts. More information about this can be read here.

There are two solutions for this problem. First, libsodium.dylib can symlinked into the Tribler root directory. This can be done by executing the following command in the Tribler root directory:

ln -s /usr/local/lib/libsodium.dylib

Now the ctypes Python library will be able to find the libsodium.dylib file.

The second solution is to disable SIP. This is not recommended since it makes the system more vulnerable for attacks. Information about disabling SIP can be found here.

Linux

This section contains information about setting up a Tribler development environment on Linux systems.

Debian/Ubuntu/Mint

Execute the following command in your terminal:

sudo apt-get install libav-tools libjs-excanvas libjs-mootools libsodium13 libx11-6 python-apsw python-cherrypy3 python-crypto python-cryptography python-feedparser python-leveldb python-libtorrent python-m2crypto python-netifaces python-pil python-pyasn1 python-twisted python-wxgtk2.8 python2.7 vlc python-pip python-chardet python-configobj
sudo pip install decorator libnacl

Experimental support for Ubuntu 16.04

Please try if the latest experimental build works for you.

bash
sudo apt-get install libsodium-dev python-nacl

Next, download the latest .deb file from here.

Installing libsodium13 and python-cryptography on Ubuntu 14.04

While installing libsodium13 and python-cryptography on a clean Ubuntu 14.04 install (possibly other versions as well), the situation can occur where the Ubuntu terminal throws the following error when trying to install the dependencies mentioned earlier in the README.rst:

E: Unable to locate package libsodium13 E: Unable to locate package python-cryptography

This means that the required packages are not directly in the available package list of Ubuntu 14.04.

To install the packages, the required files have to be downloaded from their respecive websites.

For libsodium13, download libsodium13\_1.0.1-1\_<ProcessorType\>.deb from http://packages.ubuntu.com/vivid/libsodium13](http://packages.ubuntu.com/vivid/libsodium13

For python-cryptography, download python-cryptography\_0.8-1ubuntu2\_<ProcessorType\>.deb from http://packages.ubuntu.com/vivid/python-cryptography.

Installing the files Through terminal

After downloading files go to the download folder and install the files through terminal:

For amd64:

cd ./Downloads
dpkg -i libsodium13_1.0.1-1_amd64.deb
dpkg -i python-cryptography_0.8-1ubuntu2_amd64.deb

For i386:

cd ./Downloads
dpkg -i libsodium13_1.0.1-1_i386.deb
dpkg -i python-cryptography_0.8-1ubuntu2_i386.deb

Through file navigator:

Using the file navigator to go to the download folder and by clicking on the .deb files to have the software installer install the packages.

Now installing the list of dependencies should no longer throw an error.

If there are any problems with the guide above, please feel free to fix any errors or create an issue so we can look into it.

Arch Linux

Execute the following command in your terminal:

sudo pacman -S libsodium libtorrent-rasterbar python2-apsw python2-cherrypy python2-cryptography python2-decorator python2-feedparser python2-gmpy2 python2-m2crypto python2-netifaces python2-pillow python2-plyvel python2-twisted wxpython2.8