Reputation: 125
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.
Upvotes: 1
Views: 8178
Reputation: 668
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.
libtorrent
for Python without building itFor 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.
libtorrent
for Python on Windows 7In order to get boost
working, you will first have to download and install:
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!
Upvotes: 3