Installing libtorrent for Python 3.6 on Windows 7
Asked Answered
T

1

1

Windows 7 x64 - Python 3.6

I am trying to install the libtorrent Python library in windows using the instructions here.

After navigating to the setup.py file, I used the following commands

python setup.py build
python setup.py install

In the cmd window, I get the following messages:

C:\Users\thomas\Desktop\libtorrent-master>python setup.py build
running build

C:\Users\thomas\Desktop\libtorrent-master>python setup.py install
running install
running build
running install_egg_info
Removing C:\Users\thomas\AppData\Local\Programs\Python\Python36-32\Lib\site-pac
kages\python_libtorrent-1.2.0-py3.6.egg-info
Writing C:\Users\thomas\AppData\Local\Programs\Python\Python36-32\Lib\site-pack
ages\python_libtorrent-1.2.0-py3.6.egg-info

What else do I need to do? Because trying to import the libtorrent library, the interpreter comes up with this message:

>>> import libtorrent
Traceback (most recent call last):
File , line 1, in
ModuleNotFoundError: No module named 'libtorrent'

No matter what, the proper DLL is not available in the Python folder and thus I can't import the library.

Using the MSI installer from the Sourceforge link doesn't help either since it's severely outdated.

Thetic answered 18/4, 2017 at 17:39 Comment(1)
You can install it with pip using this wheel if you are on 64-bit Python or this for 32. Just till I write a full answer...Phlox
P
3

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:

  1. Windows 7 SDK and .NET Framework 4

  2. Microsoft Visual C++ 2015 Build Tools

After you are done installing those, you will have to add their directories to your PATH:

  1. Right-Click Computer and go to Properties:

    Right-Click <code>Computer</code> and go to <code>Properties</code>

  2. Click Advanced System Settings at the left:

    Advanced System Settings

  3. Click Environment Variables at the bottom-right:

    Environment Variables

  4. Choose PATH from the top list and click Edit...:

    PATH

  5. 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\
    
  6. 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:

  1. Extract it

  2. Open a Command Prompt and cd into the extracted directory

  3. 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.

  1. Open a new Command Prompt

  2. 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:

  1. Download and extract the repository

  2. Open <libtorrent extracted directory>\include\libtorrent\session.hpp in a notepad, find the line that starts with std::snprintf, remove std:: and save.

  3. In a Command Prompt, cd into <libtorrent extracted directory>\bindings\python

  4. 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

  5. Just be patient, when it finishes you will have a libtorrent.pyd in <libtorrent extracted directory>\bindings\python which you can import inside Python!

Phlox answered 24/8, 2017 at 15:26 Comment(7)
Which windows SDK do i need for windows 10? I am trying to follow your answer, but it seems like for windows 10, the SDK is different?Washwoman
I remember struggling to make this work for windows 10, the files of the SDK seemed to be different. Could you tell me in which step you are? I will take a look at it againPhlox
Hey @Stam Kaly, thanks for replying! I'm at step 1 actually. I couldnt find the equivalent of Windows 7 SDK and .NET Framework 4. Then it leads to issues with step 5 when i'm trying to add it to path. Really appreciate the help!!Washwoman
This is where you should get the SDK from. The paths will be different so don't move on to the next step.Phlox
Okay thanks for it! let me try it out and see if I can figure out how to do it. If it doesn't work, perhaps I could open a question thread and maybe if you have the time, you could help guide me along? (:Washwoman
Sure, I could help you with any problems you face!Phlox
Because I don't have windows anymore, my answer won't help you much, but I have some things in mind that could help. Check if this folder exists: "C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0" and e-mail me at [email protected] we'll talk about it from there and once I have enough info I will give you a full answer!Phlox

© 2022 - 2024 — McMap. All rights reserved.