gpt4 book ai didi

python - 导入 BitTorrent bencode 模块

转载 作者:太空宇宙 更新时间:2023-11-03 23:49:42 25 4
gpt4 key购买 nike

我使用的是 Mac OS X 10.6。 Python 是 2.6.1。我已经安装了 bencode 模块作为

sudo easy_install BitTorrent-bencode

它出现在站点包中

/Library/Python/2.6/site-packages/BitTorrent_bencode-5.0.8-py2.6.egg

但是,如何导入和使用这个模块呢?

>>> import bencode

不工作...

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named bencode

如何从站点包中导入模块?如何识别模块名称 BitTorrent_bencode-5.0.8-py2.6.egg 包含?

sys.path ['', '/Library/Python/2.6/site-packages/BitTorrent_bencode-5.0.8-py2.6.egg', '/Library/Python/2.6/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload', '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC', '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/wx-2.8-mac-unicode']

谢谢

最佳答案

BitTorrent_bencode-5.0.8-py2.4.egg 已损坏。如果您使用解压缩查看 egg 的内容,您会看到:

$ unzip BitTorrent_bencode-5.0.8-py2.6.egg                                                                                                                                                                                                                         
Archive: BitTorrent_bencode-5.0.8-py2.6.egg
inflating: EGG-INFO/dependency_links.txt
inflating: EGG-INFO/PKG-INFO
inflating: EGG-INFO/SOURCES.txt
inflating: EGG-INFO/top_level.txt
inflating: EGG-INFO/zip-safe
inflating: test/__init__.py
inflating: test/__init__.pyc
inflating: test/benchmarkbencode.py
inflating: test/benchmarkbencode.pyc
inflating: test/benchmarkdata.py
inflating: test/benchmarkdata.pyc
inflating: test/testbencode.py
inflating: test/testbencode.pyc

请注意,不包括 bencode.py 和 BTL.py。如果您从 pypi 下载包的源代码分发,你可以得到丢失的文件。该包的问题是 setup.py 没有在创建 egg 的包列表中包含发行版的根目录。要解决此问题,您可以编辑 setup.py 并替换以下行:

     packages = find_packages(),

与:

     packages = ['','test'],

然后,运行 python setup.py install 将正确安装包。

关于python - 导入 BitTorrent bencode 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2693963/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com