导入 BitTorrent Bencode 模块
我使用的是 Mac OS X 10.6。 Python 是 2.6.1。 我已经安装了 Bencode 模块
sudo easy_install BitTorrent-bencode
它出现在 site-packages 中
/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包含的模块名称?
<块引用> <块引用>系统路径 ['','/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/版本/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/库/框架/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']
谢谢
I'm on Mac OS X 10.6. Python is 2.6.1.
I've installed bencode module as
sudo easy_install BitTorrent-bencode
It appeared in site-packages
/Library/Python/2.6/site-packages/BitTorrent_bencode-5.0.8-py2.6.egg
But, how to import and use this module?
>>> import bencode
doesn't work...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named bencode
How to import modules from site-packages?
How to recognize module name BitTorrent_bencode-5.0.8-py2.6.egg contains?
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']
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
BitTorrent_bencode-5.0.8-py2.4.egg 已损坏。如果您使用 unzip 查看 Egg 的内容,您将看到:
请注意,不包括 bencode.py 和 BTL.py。如果您从 pypi,即可获取丢失的文件。该包的问题在于 setup.py 未将发行版的根目录包含在创建 Egg 的包列表中。要解决此问题,您可以编辑 setup.py 并将以下行替换
为:
然后,运行 python setup.py install 将正确安装该软件包。
The BitTorrent_bencode-5.0.8-py2.4.egg is broken. If you use unzip to look at the contents of the egg you'll see:
Notice that bencode.py and BTL.py are not included. If you download the source distribution for the package from pypi, you can get the missing files. The problem with the package is that the setup.py does not include the root directory of the distribution in the list of packages that the egg is created by. To fix this you could edit setup.py and replace the line that says:
with:
Then, running
python setup.py install
will correctly install the package.使用 pip install bencode.py
而不是 pip install bencode
use pip install bencode.py
rather than pip install bencode
据我所知,pypi 上的 BitTorrent_bencode-5.0.8-py2.4.egg 不包含 bencode.py。
我会下载 sources 并手动将 bencode.py 和 BTL.py 复制到您的 site-packages 文件夹中。
From what i see, BitTorrent_bencode-5.0.8-py2.4.egg on pypi does not containt bencode.py.
I would download sources and manually copy bencode.py and BTL.py in your site-packages folder.
您也可以使用
bzrlib.bencode
包。这将使用easy_install
或pip
进行安装。You can alternatively use the
bzrlib.bencode
package. This installs witheasy_install
orpip
.方法是将.egg 添加到
sys.path
中。最简单的方法就是将 .pth 文件放入site-packages/
中,其中包含彩蛋的文件名:BitTorrent_bencode.pth
:如果此时仍然无法正确导入,则模块或包名称可能有误。在可以打开 .zip 文件的工具中打开 .egg 文件并检查内部结构以获取提示。
The way to do it is to add the .egg to
sys.path
. The easiest way to do that is to drop a .pth file intosite-packages/
containing the filename of the egg:BitTorrent_bencode.pth
:If it still doesn't import properly at this point then you may have the module or package name wrong. Open the .egg file in something that can open .zip files and examine the internal structure for hints.