在Windows 7上为Python 3.6安装libtorrent [英] Installing libtorrent for Python 3.6 on Windows 7
问题描述
Windows 7 x64-Python 3.6
我正在尝试使用导航到setup.py文件后,我使用了以下命令
After navigating to the setup.py file, I used the following commands
python setup.py build
python setup.py install
在cmd窗口中,我收到以下消息:
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
我还需要做什么?因为尝试导入libtorrent库,所以解释器会显示以下消息:
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'
无论如何,Python文件夹中没有正确的DLL,因此我无法导入该库.
No matter what, the proper DLL is not available in the Python folder and thus I can't import the library.
使用Sourceforge链接中的MSI安装程序也无济于事,因为它已经严重过时.
Using the MSI installer from the Sourceforge link doesn't help either since it's severely outdated.
推荐答案
如果快速浏览要安装的setup.py
文件,则可以 boost C++ libraries
,以便生成Python所需的libtorrent.pyd
.您会期望得到一个错误,但是现在情况并非如此.
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
的Python Wheels,可以将其与pip install
一起安装.请考虑一下,如果它不起作用,则意味着您将必须为计算机构建自己的.pyd
.
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.
为了使boost
工作,您首先必须下载并安装:
In order to get boost
working, you will first have to download and install:
Microsoft Visual C ++ 2015构建 工具
Microsoft Visual C++ 2015 Build Tools
安装完这些文件后,必须将其目录添加到PATH
:
After you are done installing those, you will have to add their directories to your PATH
:
-
右键单击
Computer
并转到Properties
:
单击左侧的Advanced System Settings
:
单击右下角的Environment Variables
:
从顶部列表中选择PATH
,然后单击Edit...
:
Choose PATH
from the top list and click Edit...
:
如果要构建,请在弹出的框中添加这些内容 对于32位Python:
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\
或者这些用于64位:
;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\
从弹出窗口和Environment Variables
中单击OK
窗口,而另一个窗口保持打开状态,稍后我们将需要它..
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..
现在一切都已设置好,您就可以安装 boost C++ libraries
了.因为libtorrent
的Python绑定具有一些问题,其增强版本高于
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
在提取的目录中打开Command Prompt
和cd
Open a Command Prompt
and cd
into the extracted directory
运行bootstrap.bat
安装库
完成此操作后,转到您先前未打开的System Properties
窗口,然后再次单击Environment Variables
.
点击New...
并添加以下内容:
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>"
,然后再次单击OK
进入两个窗口.
and click OK
to both windows again.
要真正开始构建libtorrent
,还有最后一步,那就是在配置文件中指定Python版本.
There is one last step before you can actually start building libtorrent
, and that is specifying your Python version into a configuration file.
-
打开一个新
Command Prompt
执行
echo using python : <Python Version> : "<Python Path>" : "<Python Path>\Include" : "<Python Path>\libs" ; >> user-config.jam
例如:
echo using python : 3.5 : "C:\Program Files\Python35" : "C:\Program Files\Python35\Include" : "C:\Program Files\Python35\libs" ; >> user-config.jam
现在要构建libtorrent
:
在记事本中打开<libtorrent extracted directory>\include\libtorrent\session.hpp
,找到以std::snprintf
开头的行,删除std::
并保存.
Open <libtorrent extracted directory>\include\libtorrent\session.hpp
in a notepad, find the line that starts with std::snprintf
, remove std::
and save.
在Command Prompt
中,将cd
插入<libtorrent extracted
directory>\bindings\python
In a Command Prompt
, cd
into <libtorrent extracted
directory>\bindings\python
现在
如果要构建32位Python,请执行:
if you are building for 32-bit Python execute:
bjam libtorrent-link=static boost-link=static stage_module
或
bjam libtorrent-link=static boost-link=static address-model=64 stage_module
用于64位
请耐心等待,完成后您将得到一个libtorrent.pyd
在<libtorrent extracted directory>\bindings\python
中,您可以
导入Python!
Just be patient, when it finishes you will have a libtorrent.pyd
in <libtorrent extracted directory>\bindings\python
which you can
import inside Python!
这篇关于在Windows 7上为Python 3.6安装libtorrent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!