SublimeText3: ImportError: No module named ‘urllib2′

使用sublime text的同学一般会装package control这个插件,这个插件是管理插件的功能,先安装它,再安装其他插件就方便了。

console安装命令:

import  urllib2 , os ;pf = 'Package Control.sublime-package' ;ipp =sublime. installed_packages_path ( ) ; os. makedirs (ipp )  if  not  os. path. exists (ipp )  else  None ; open ( os. path. join (ipp ,pf ) , 'wb' ). write ( urllib2. urlopen ( 'http://sublime.wbond.net/'+pf. replace ( ' ' , '%20' ) ). read ( ) )
      sublimetext2使用以上命令是没问题的,但是在SublimeText3中会提示ImportError: No module named ‘urllib2′,这是因为SublimeText3内置的Python版本是3,已经不支持urllib2,只要改成以下命令就可以了:

import  urllib. request , os ;pf  =  'Package Control.sublime-package' ;ipp  = sublime. installed_packages_path ( ) ;  urllib. request. install_opener (  urllib. request. build_opener (  urllib. request. ProxyHandler ( ) )  ) ; open ( os. path. join (ipp , pf ) ,  'wb' ). write ( urllib. request. urlopen (  'http://sublime.wbond.net/' + pf. replace ( ' ' , '%20' ) ). read ( ) )




你可能感兴趣的:(SublimeText3: ImportError: No module named ‘urllib2′)