问题
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.
回答1:
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.
Wheel for Python 3.5 32-bit
Wheel for Python 3.5 64-bit
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
Computerand go toProperties:Click
Advanced System Settingsat the left:Click
Environment Variablesat the bottom-right:Choose
PATHfrom the top list and clickEdit...: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
OKboth from the pop up and from theEnvironment Variableswindow, 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 Promptandcdinto the extracted directoryRun
bootstrap.batto 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 PromptExecute
echo using python : <Python Version> : "<Python Path>" : "<Python Path>\Include" : "<Python Path>\libs" ; >> user-config.jamFor 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.hppin a notepad, find the line that starts withstd::snprintf, removestd::and save.In a
Command Prompt,cdinto<libtorrent extracted directory>\bindings\pythonNow
if you are building for 32-bit Python execute:
bjam libtorrent-link=static boost-link=static stage_moduleor
bjam libtorrent-link=static boost-link=static address-model=64 stage_modulefor 64-bitJust be patient, when it finishes you will have a
libtorrent.pydin<libtorrent extracted directory>\bindings\pythonwhich you can import inside Python!
来源:https://stackoverflow.com/questions/43478842/installing-libtorrent-for-python-3-6-on-windows-7