libtorrent-rasterbar 的 python 绑定是不是适用于 Python 3?

Posted

技术标签:

【中文标题】libtorrent-rasterbar 的 python 绑定是不是适用于 Python 3?【英文标题】:Do the python bindings for libtorrent-rasterbar work with Python 3 ?libtorrent-rasterbar 的 python 绑定是否适用于 Python 3? 【发布时间】:2014-06-06 03:11:30 【问题描述】:

我安装了 Python 3.4(32 位),并在其上安装了 python-libtorrent-0.16.16.win32.msi。

我的测试代码说: ImportError: DLL 加载失败: %1 不是有效的 Win32 应用程序。

我的谷歌搜索结果表明这适用于 Python 2.7。那是解决方案吗?我必须降级我的 Python 吗?

【问题讨论】:

确实存在 debian package 和 pull request 可以做你想做的事,所以理论上应该是可能的。但是请注意,这并不一定意味着它在 Windows 上很容易。但是,Python 2 和 Python 3 很容易共存——这不是降级,因为您应该能够同时安装 Python 2 和 Python 3。 二进制文件是针对 python 2.7 构建的。如果你自己构建它,你很可能让它在 python 3 上工作 尽管有下面的答案,来自 Debian 软件包 python3-libtorrent 的绑定现在工作正常。试一试。 最新版本的 libtorrent 可以编译并在 python 3 上正常工作。但我找不到有效的安装程序。所以你可能必须手动编译它。我刚刚用 MSVS 2010 Express 完成了它。更详细的构建方法请见官方website 【参考方案1】:

没有。 Libtorrent 不支持 Python 3。

由于 Python 3 utf8 处理差异,它可以编译但无法工作。 前段时间曾尝试让它工作但没有成功 https://code.google.com/p/libtorrent/issues/detail?id=449

当前主干甚至包含无效的 Python 3,即 http://sourceforge.net/p/libtorrent/code/HEAD/tree/trunk/bindings/python/setup.py 第 70 行 > '打印命令行'

由于某种原因,有一个 Ubuntu python3-libtorrent 软件包让人感到困惑,但它肯定不起作用,手动编译也没有。

steps:
apt-get build-dep libtorrent-rasterbar
export 'PYTHON_VERSION=3.4'; export 'PYTHON=/usr/bin/python3.34'
./configure LDFLAGS="-L/usr/lib/python3.4/config-3.4m-x86_64-linux-gnu/" --enable-python-binding --enable-geoip=no
--with-boost-python=boost_python-py34
ldconfig

>> python
import libtorrent
ses = libtorrent.session()
ses.save_state()

"UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa2 in position 0: invalid start byte"

【讨论】:

出于某种原因,有一个 Ubuntu python3-libtorrent 软件包让人们感到困惑,但它肯定不起作用,手动编译也不起作用。 多么好,典型的开源。 我已经将 libtorrent 与 Python 3 一起使用,因此您可能应该更新您的答案以反映当前状态,以防人们遇到它。问题已得到修复。【参考方案2】:

确实支持python3

这个 docker 文件对我有用(libtorrent - 带有 lib 的本地目录已检出为所需的版本)

FROM debian:buster-slim

WORKDIR /app/libtorrent
COPY debian/backports.list /etc/apt/sources.list.d/
RUN apt-get update
RUN apt-get install -y -t buster-backports checkinstall
RUN apt-get install -y build-essential libboost-system-dev libboost-python-dev libboost-chrono-dev libboost-random-dev libssl-dev
RUN apt-get install -y autoconf automake libtool
ADD libtorrent /app/libtorrent
RUN ./autotool.sh
# RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.7 1
ENV PYTHON=/usr/bin/python3.7
RUN ./configure --enable-python-binding --with-libiconv
RUN make
RUN checkinstall
RUN ldconfig

【讨论】:

以上是关于libtorrent-rasterbar 的 python 绑定是不是适用于 Python 3?的主要内容,如果未能解决你的问题,请参考以下文章

libtorrent-rasterbar 的 python 绑定是不是适用于 Python 3?

libtorrent-rasterbar 和 QGuiApplication 导致内存损坏

导入 libtorrent 不工作

使用 P2P 将文件下载到远程服务器

python py文件中执行另一个py文件

discord.py和discord.py的区别[voice]