Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 导入BitTorrent bencode模块_Python_Macos_Egg - Fatal编程技术网

Python 导入BitTorrent bencode模块

Python 导入BitTorrent bencode模块,python,macos,egg,Python,Macos,Egg,我使用的是MacOSX10.6。Python是2.6.1。 我已将bencode模块安装为 sudo easy_安装BitTorrent bencode 它出现在网站包中 /Library/Python/2.6/site-packages/BitTorrent_bencode-5.0.8-py2.6.egg 但是,如何导入和使用此模块 >>> import bencode 不起作用 Traceback (most recent call last): File "<

我使用的是MacOSX10.6。Python是2.6.1。 我已将bencode模块安装为

sudo easy_安装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
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
ImportError:没有名为bencode的模块
如何从站点包导入模块? 如何识别模块名BitTorrent_bencode-5.0.8-py2.6.1

系统路径 [“”,/Library/Python/2.6/site packages/BitTorrentbencode-5.0.8-py2.6.egg',“/Library/Python/2.6/site packages',”/System/Library/python26.zip',/System/Library/Frameworks/python26.zip',“/framework/Versions/2.6/lib/python2.6',“/System/libraphs/Frameworks/Frameworks/Versions/2.6/python26/plat-darwin”“/System/Library/Frameworks/Python.Frameworks/Versions/2.6/lib/python2.6/plat-mac”“,”/System/Library/Frameworks/python2.6/plat-mac/lib scriptpackages”“,“/System/Library/Frameworks/Versions/2.6/Extras/lib/Python”“,”/System/lib/lib/Frameworks/python2.6/lib-tk”“,“/S”System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib old','/System/Library/Frameworks/python2.6/lib dynload','/System/Library/Frameworks/Python.6/python2.6/lib/pythobjc','/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/wx-2.8-mac-unicode']


谢谢

方法是将.egg添加到
sys.path
。最简单的方法是将.pth文件放入包含egg文件名的
site packages/

BitTorrent\u bencode.pth

BitTorrent_bencode-5.0.8-py2.6.egg

如果此时仍无法正确导入,则可能是模块或包名错误。在可以打开.zip文件的文件中打开.egg文件,并检查内部结构以获取提示。

据我所见,pypi上的BitTorrent_bencode-5.0.8-py2.4.egg不包含bencode.py。

我会下载并手动复制你网站包文件夹中的bencode.py和BTL.py。

BitTorrent_bencode-5.0.8-py2.4.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。如果从下载包的源发行版,则可以获取丢失的文件。该包的问题在于setup.py在创建egg的包列表中不包括发行版的根目录。要解决此问题,可以编辑setup.py并替换显示以下内容的行:

     packages = find_packages(),
与:

     packages = ['','test'],

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

您也可以使用
bzrlib.bencode
软件包。这将使用
easy\u install
pip

使用pip install bencode.py安装


与pip install bencode不同的是,已有easy-install.pth包含“import sys;sys.\u plen=len(sys.path)。/BitTorrent\u bencode-5.0.8-py2.6.egg import sys;new=sys.path[sys.\u plen:];del sys.path[sys.\u plen:];p=getattr(sys,“\u egginsert',',0);sys.path[p:p]=new;sys.\u eggsert=p+len(new)”这足够了吗?当然。在这种情况下,你应该继续回答我的其余问题。如果这也没有产生任何结果,那么鸡蛋本身就坏了,您应该通知上游。有关更多信息,请键入达尔文的Python 2.6.1(r261:675152010年2月11日,00:51:29)[GCC 4.2.1(Apple Inc.build 5646)]上的“帮助”、“版权”、“信用”或“许可证”。>>从BitTorrent.bencode导入bencode回溯(上次调用):文件“”,第1行,在ImportError中:没有名为BitTorrent.bencode的模块:-(我正在更改我的答案,因为我在Osx上尝试使用pip,但我得到了相同的错误。我尝试dezip.egg,但没有找到源代码。好的,谢谢!事实上,我已经手动将bencode.py和BTL.py复制到站点包。无论如何,这仍然不正确——正确的输入应该是'py_modules=“bencode”,并将“packages”行完全删除。