3

I'm trying to install Sublime Package Control as explained here http://wbond.net/sublime_packages/package_control/installation but get an error:

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

There is some answer related to the problem (Python 3.2 Unable to import urllib2 (ImportError: No module named urllib2)) but it doesn't explain how to solve it, a user just posted a link explaining why the problem appears. But how to use that info to solve the problem?

This is a command for installation:

import urllib2,os; 
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()));
open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read()); 
print('Please restart Sublime Text to finish installation')

What with should I replace urllib2 to succeed installation?

Community
  • 1
  • 1
Green
  • 28,742
  • 61
  • 158
  • 247

3 Answers3

11

It appears that you followed the instructions for installing on Sublime Text 2. For now on Sublime Text 3 you must install using git. The instructions from the site follows:

cd Packages/
git clone https://github.com/wbond/sublime_package_control.git "Package Control"
cd "Package Control"
git checkout python3

Note: The Packages/ folder on the first line refers to the folder that opens when you use the Preferences > Browse Packages… menu.

Here is a link to the relavant section of the page

zchrykng
  • 1,066
  • 1
  • 10
  • 20
4

It seems that for Sublime Text 3 the Git method is not needed, at least not anymore.

Here's the snippet for ST3:

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())
MattDMo
  • 100,794
  • 21
  • 241
  • 231
joonas.fi
  • 7,478
  • 2
  • 29
  • 17
0

I solve the same error for Sublime Text 2 with this:

import urllib.request,os,hashlib; h = '2915d1851351e5ee549c20394736b442' + '8bc59f460fa1548d1514676163dafc88'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); os.makedirs( ipp ) if not os.path.exists(ipp) else None; urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://packagecontrol.io/' + 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')
pableiros
  • 14,932
  • 12
  • 99
  • 105