我正在尝试将 libtorrent 添加到我的 Python 中。我的问题是,即使我尝试了许多虽然奇怪的解决方法(稍后会详细介绍)来让 libtorrent 与我的 Python 一起工作,但我终生无法导入模块。
我将介绍我尝试过的内容。我偶然发现了部分帮助我的“解决方案”,但不是一直帮助我。我什至尝试按照自己在Stack Overflow上提供的创建者的说明进行操作。
让我们退后几步,观察我尝试过的操作。我们将从提升开始。如果您不知道,libtorrent 需要 boost 才能运行。当涉及到提升时,我的知识并不丰富,因此我将不再解释。所以,就像我遵循的所有说明一样,说需要提升。我及时安装了 boost 并将其路径添加到环境表中。我随后运行了 boost 中提供的 bat 文件,它创建了两个文件(可能更多)B2.exe和BJAM。B2是我在接下来的步骤中需要使用的。
我继续进入下载的 boost 文件夹 (ver 1.66) > tools > build > example,然后编辑 user-config.jam 文件并添加以下项目:
使用 msvc:14.0;
使用 gcc : : -std=c++11 ;
使用 python:3.6:C:\Users\XXXX\AppData\Local\Programs\Python\Python36-32:C:\Users\XXXX\AppData\Local\Programs\Python\Python36-32\include:C:\Users\ XXXX\AppData\Local\Programs\Python\Python36-32\libs ;
然后,我继续为 VS2017 打开提升的x64 本机工具命令提示符并执行以下命令
b2.exe --hash openssl-version=pre1.1 link=shared libtorrent-link=shared stage_module stage_dependencies
也是由 Arvid 提供的(我相信是创建者),在libtorrent>bindings>python文件夹中这开始了 5 分钟的下载时间。它给了我以下信息:
Performing configuration checks
- 32-bit : yes (cached)
- arm : no (cached)
- mips1 : no (cached)
- power : no (cached)
- sparc : no (cached)
- x86 : yes (cached)
- symlinks supported : yes (cached)
...patience...
...patience...
...patience...
...found 7252 targets...
...updating 27 targets...
最后说它
...updated 27 targets...
说明基本上到此为止,因此您会认为它现在已正确配置。不是。我立即去了 bindings>python 文件夹,果然,存在 libtorrent.pyd 和 libtorrent.lib 文件。看起来很有希望。我启动了一个命令提示符,检查了 Pip(pip 列表)并在列表中看到了 libtorrent。进入python并尝试导入libtorrent。
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import libtorrent
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: DLL load failed: The specified module could not be found.
pyd文件存在,所以我尝试手动将它拖到python DLL文件夹中,仍然无法导入它。我什至还做了一本手册
sys.path.append('D:\Downloads\libtorrent-rasterbar-1.1.7\libtorrent-
rasterbar-1.1.7\bindings\python')
有些人建议这样做,因为它可能没有联系。
我很茫然。
我无法导入它,但它显然不仅存在于 pip 列表中,而且存在于libtorrent > bindings > python 文件夹(pyd 和 lib 文件)中。
我也尝试过运行 setup.py 文件。哪个做同样的事情,但没有让我更进一步。
我做了一个观察:libtorrent > bindings > python > bin文件夹中的文件夹有一个奇怪的名称:“d796976f6d11336977dac24301151009”包含一个 src 文件夹、libtorrent.exp、libtorrent.lib、libtorrent.pdb、libtorrent.pyd、libtorrent.pyd .manifest 和 libtorrent.pyd.rsp
在我看来,安装或下载尚未完全完成。然而,这可能不是这个,这只是一个没有受过教育的猜测。此外,在libtorrent > bindings > python文件夹 & 中找到的 libtorrent.lib 文件和 libtorrent.pyd 文件的大小分别为 2 KB 和 3000 KB
会不会坏了?我没有正确链接它吗?
我正在使用 Python 3.6.5 32 位(也存在 64 位,但由于某种原因根本无法与 libtorrent 一起使用)。安装了 Windows 10 的基于 Windows 的 64 位系统。提升 1.66.0。尝试下载/安装/导入 libtorrent-rasterbar-1.1.7