ImportError when trying to install Package Control in Sublime Text 2

Lazarus

I tried installing Package Control in Sublime Text 2. I entered the following install code from the official website into the console:

import urllib2,os,hashlib; 
h = '7183a2d3e96f11eeadd761d777e62404' + 'e330c659d4bb41d3bdf022e94cab3cd0'; 
pf = 'Package Control.sublime-package'; 
ipp = sublime.installed_packages_path(); 
os.makedirs( ipp ) if not os.path.exists(ipp) else None; 
urllib2.install_opener( urllib2.build_opener( urllib2.ProxyHandler()) ); 
by = urllib2.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ', '%20')).read(); 
dh = hashlib.sha256(by).hexdigest(); 
open( os.path.join( ipp, pf), 'wb' ).write(by) if dh == h else None; 
print('Error validating download (got %s instead of %s), please try manual install' % (dh, h) if dh != h else 'Please restart Sublime Text to finish installation')`

However, the only result I got was:

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

I don't understand why urllib2 isn't there. I checked which version of Python Sublime is using and it's 3.3.3.

>>> import sys
>>> print(sys.version)
3.3.3 (default, Dec 19 2013, 14:22:24) 
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.24)]

Any ideas?

abarnert

The problem is that you're using Python 3, and you're following instructions for Python 2.

Among the many differences between the two languages is that Python 3 reorganized urllib2 and a bunch of related modules into the urllib package. In particular, the urlopen function, the ProxyHandler class, etc. are now in urllib.request instead of urlopen.

However, you'd probably do better looking for Python 3 instructions than trying to hack up the Python 2 instructions to work.

Especially since, if there aren't any Python 3 instructions, there's a decent possibility that the program doesn't work with Python 3 and will just end up leaving unusable garbage in your site-packages or Sublime plugins or something.

Even more so because usually if you're using Python 3 with Sublime Text, you're actually using Sublime Text 3 beta, which has some changes of its own from Sublime Text 2.

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

尝试在Sublime Text 2中安装Package Control时出现ImportError

来自分类Dev

Sublime Text 2-已安装Package Control,但未显示列表

来自分类Dev

Sublime Text Package Control搜索无法正常工作

来自分类Dev

Sublime Text Package Control搜索无法正常工作

来自分类Dev

从Sublime Text 2运行npm install不起作用

来自分类Dev

卸载Sublime Text 2

来自分类Dev

在Sublime Text中使用Pylinter时出现ImportError

来自分类常见问题

Sublime Text 2多行编辑

来自分类Dev

如何更新Sublime Text 2?

来自分类Dev

Sublime Text 2构建系统

来自分类Dev

如何更新Sublime Text 2?

来自分类Dev

Sublime Text 2 Terminal插件

来自分类Dev

为什么Sublime Package Control不起作用?

来自分类Dev

有没有一种方法可以使用Package Control回滚到Sublime Text插件的先前版本?

来自分类Dev

将Sublime Text 2与Karma集成

来自分类Dev

How to run PHP code in Sublime Text 2

来自分类Dev

Sublime Text 2代码提示

来自分类Dev

从终端问题中打开Sublime Text 2

来自分类Dev

Sublime Text 2中的多行CoffeeScript REPL

来自分类Dev

Sublime Text 2 PHP高亮显示

来自分类Dev

Sublime Text 2 + Emmet-扩展无效

来自分类Dev

在Sublime Text 2中解包文本

来自分类Dev

如何使用Sublime Text 2(如Notepad ++)

来自分类Dev

Sublime Text 2和Emmet和换行

来自分类Dev

Sublime Text 2 + SublimeREPL中的键绑定

来自分类Dev

Sublime Text 2删除唯一的行

来自分类Dev

Sublime Text 2 LatexTools无法启动SumatraPDF

来自分类Dev

Sublime Text 2不同的缩进设置

来自分类Dev

Sublime Text 2的phpfmt插件不再可用?