If you took a quick look at the setup.py
file you are trying to install, you would see that it assumes you have installed the boost C++ libraries
in order to generate the libtorrent.pyd
required for Python. You would expect to get an error, but that's not how things are right now.
Installing libtorrent
for Python without building it
For your own convenience, I have built Python Wheels of libtorrent
which can be installed with pip install
. Please take into consideration, that if it does not work, it means you will have to build your own .pyd
for your machine.
Building and installing libtorrent
for Python on Windows 7
In order to get boost
working, you will first have to download and install:
Windows 7 SDK and .NET Framework
4
Microsoft Visual C++ 2015 Build
Tools
After you are done installing those, you will have to add their directories to your PATH
:
Right-Click Computer
and go to Properties
:
Click Advanced System Settings
at the left:
Click Environment Variables
at the bottom-right:
Choose PATH
from the top list and click Edit...
:
Inside the box that popped up add these if you want to be building
for 32-bit Python:
;C:\Program Files\Microsoft SDKs\Windows\v7.1\Include;C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\;C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\
Or these for 64-bit:
;C:\Program Files\Microsoft SDKs\Windows\v7.1\Include;C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\x64;C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\x64;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\
Click OK
both from the pop up and from the Environment Variables
window, and leave the other one opened, we will need it later on..
Now everything is set up and you are ready to install the boost C++ libraries
. Because libtorrent
's Python bindings have some issues with boost versions higher than 1.63
(in August 2017), make sure to download this one.
After you have downloaded it:
Extract it
Open a Command Prompt
and cd
into the extracted directory
Run bootstrap.bat
to install the libraries
After that is done, go to the System Properties
window you left open from earlier, and click Environment Variables
again.
Click on New...
and add these:
Variable name: BOOST_ROOT
Variable value: "<full path to extracted directory of boost>"
and click OK
to both windows again.
There is one last step before you can actually start building libtorrent
, and that is specifying your Python version into a configuration file.
Open a new Command Prompt
Execute
echo using python : <Python Version> : "<Python Path>" : "<Python Path>\Include" : "<Python Path>\libs" ; >> user-config.jam
For example:
echo using python : 3.5 : "C:\Program Files\Python35" : "C:\Program Files\Python35\Include" : "C:\Program Files\Python35\libs" ; >> user-config.jam
Now to build libtorrent
:
Download
and extract the repository
Open <libtorrent extracted directory>\include\libtorrent\session.hpp
in a notepad, find the line that starts with std::snprintf
, remove std::
and save.
In a Command Prompt
, cd
into <libtorrent extracted
directory>\bindings\python
Now
if you are building for 32-bit Python execute:
bjam libtorrent-link=static boost-link=static stage_module
or
bjam libtorrent-link=static boost-link=static address-model=64 stage_module
for 64-bit
Just be patient, when it finishes you will have a libtorrent.pyd
in <libtorrent extracted directory>\bindings\python
which you can
import inside Python!
pip
using this wheel if you are on 64-bit Python or this for 32. Just till I write a full answer... – Phlox