导入 BitTorrent Bencode 模块

发布于 2024-08-30 02:47:17 字数 1725 浏览 8 评论 0原文

我使用的是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

迷爱 2024-09-06 02:47:17

BitTorrent_bencode-5.0.8-py2.4.egg 已损坏。如果您使用 unzip 查看 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 将正确安装该软件包。

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:

$ 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    

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:

     packages = find_packages(),

with:

     packages = ['','test'],

Then, running python setup.py install will correctly install the package.

偏爱自由 2024-09-06 02:47:17

使用 pip install bencode.py

而不是 pip install bencode

use pip install bencode.py

rather than pip install bencode

零崎曲识 2024-09-06 02:47:17

据我所知,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.

青春如此纠结 2024-09-06 02:47:17

您也可以使用 bzrlib.bencode 包。这将使用 easy_installpip 进行安装。

You can alternatively use the bzrlib.bencode package. This installs with easy_install or pip.

阳光①夏 2024-09-06 02:47:17

方法是将.egg 添加到sys.path 中。最简单的方法就是将 .pth 文件放入 site-packages/ 中,其中包含彩蛋的文件名:

BitTorrent_bencode.pth

BitTorrent_bencode-5.0.8-py2.6.egg

如果此时仍然无法正确导入,则模块或包名称可能有误。在可以打开 .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 into site-packages/ containing the filename of the egg:

BitTorrent_bencode.pth:

BitTorrent_bencode-5.0.8-py2.6.egg

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文