【发布时间】:2017-11-19 00:46:45
【问题描述】:
在过去的几天里,我尝试了所有方法来在 Python3 中安装 libtorrent。无论我尝试什么,我都会得到:
Python 3.6.3 |Anaconda, Inc.| (default, Oct 13 2017, 12:02:49)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import libtorrent
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'libtorrent'
我运行时没有错误:
$ sudo apt-get install python3-libtorrent
$ sudo apt-get install libtorrent-rasterbar-dev
我不太了解 libtorrent 和 libtorrent-rasterbar 之间的区别。据我所知,rasterbar 是 libtorrent 的依赖项。
PyPi page 上没有任何二进制文件,所以我不能pip install 它。
我可以从the GitHub page 下载软件包并通过运行以这种方式安装:
$ python setup.py build
$ python setup.py install
创建:
/home/<user>/anaconda3/lib/python3.6/site-packages/python_libtorrent-1.1.5-py3.6.egg-info
但仍然没有变化。这可能与我的 Python3 安装不在默认位置有关,但我不确定在安装 libtorrent 方面如何处理。
我还发现了this 类似的 SO 问题,其中接受的答案是明确的否。然而,最近有更多的 cmets 表示,从那时起,它已经成为可能,只是没有给出如何实现它的说明。
我已经完全没有想法了,无论多么荒谬,我都愿意接受任何建议。现在,我正在查看从 GitHub 页面获得的包,看看是否可以以某种方式将代码复制到我的项目目录中,然后将其作为本地模块导入,但到目前为止我运气不佳。如果这不起作用,我将考虑为原始 C++ libtorrent 库编写我自己的 Python3 包装器。但是,我在某处读到其他人在这方面尝试过但失败了,所以我并不期待成功。
编辑:
好的,我已经走得更远了。我以某种方式设法下载了一个没有配置文件或任何 makefile 的 repo 版本。现在我选对了,我运行:
$ ./configure --enable-python-bindings
$ make
$ python setup.py build
$ python setup.py install
$ python
Python 3.6.3 |Anaconda, Inc.| (default, Oct 13 2017, 12:02:49)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import libtorrent
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /usr/lib/x86_64-linux-gnu/libboost_python-py27.so.1.62.0: undefined symbol: PyClass_Type
我用谷歌搜索了这个,显然 PyClass_Type 没有在 Python3 中定义。所以它似乎仍在尝试为 Python2 构建自己,这解释了 ImportError 中的libboost_python-py27.so。建议的解决方案是使用-lboost_python3 而不是-lboost_python 编译C++ 库。 Makefile的第268行是BOOST_PYTHON_LIB = -lboost_python所以我把它改成了BOOST_PYTHON_LIB = -lboost_python3并重新运行:
$ make
$ python setup.py build
$ python setup.py
(我无法重新运行 $ ./configure --enable-python-binding,因为它会将 Makefile 恢复为再次使用 lboost-python)。不幸的是,我仍然收到相同的错误消息:undefined symbol: PyClass_Type。我对 C++ 几乎一无所知,所以我不确定我是否遗漏了关于编译库的一些非常明显的东西。
【问题讨论】:
-
libboost_python-py27.so.1.62.0 中的“27”指的是python 2.7版本。您还需要为 python 3.x 构建 boost-python
-
感谢@Arvid 的回复。我从boost.org 下载了 boost 并根据此处的说明构建它:eb2.co/blog/2012/03/building-boost.python-for-python-3.2
project-config.jam将我的 python 路径列为using python : 3.6 : /home/<user>/anaconda3 ;所以我认为我不需要更改它。然后我重新运行命令来构建 libtorrent。不幸的是,我仍然遇到同样的错误。 -
顺便说一句,你是 libtorrent 开发者,对吧?在我进行故障排除时,我看到了很多关于 libtorrent 的 SO 问题的帖子。非常感谢您为 torrent 相关内容构建了如此完整的库。很高兴有一个开发人员在他们建成后继续帮助他们。更不用说如果我能让它工作,不管用多少周来破解一个更糟糕的版本,你都会拯救我
-
@Arvid 我正在尝试使用dreamingpotato.com/2015/11/21/… 提供的步骤在 conda env 中安装 libtorrent。但是我在原始问题中遇到了同样的问题。你们能提供在 conda virtualenv 中在 python 3.3 上设置 libboost 的步骤吗?我按照这篇文章gist.github.com/melvincabatuan/a5a4a10b15ef31a5a481 中的步骤操作并添加了 conda virtualenv python 3.3 路径。但仍然遇到同样的错误。
-
@VaibhavBhavsar 据我所知,无法在 conda 中设置 libtorrent。我试过没有成功。最好的办法是使用默认的 python 安装,但你也可能会遇到 virtualenv 的问题。
标签: linux python-3.x ubuntu libtorrent