Home Download Buy Blog Forum Support

sublimes python2.6, no virtualenv, import urandom error

sublimes python2.6, no virtualenv, import urandom error

Postby knifter on Tue Jul 03, 2012 10:14 am

Situation:
Currently a (small) python library distribution is installed as part of the install in the python26.zip file. You can remove this zip-file and sublime will also look for its libraries in <sublimeinstalldir>/lib/python2.6 (or '../python26' in pre-2211 versions)

The problem is that SublimeClang uses some additional libraries which can easily be installed on the local system.
F.e.: If you install the SublimeClang plugin you get a message like: "The ctypes lib cannot be imported. See http://www.github.com/quarnster/SublimeClang"
The url suggests you use pythonbrew to fix the error. It involves linking the <sublimeinstalldir>/lib/python2.6 to a 'brewed' install in ~/.pythonbrew
Instead what I did was link <sublime>/lib/python2.6 to my system-wide 2.6 install: /usr/lib/python2.6.
This has solved the problems for almost a year now.

However, 2 weeks ago an update for python has triggered a problem importing 'random':
Lots of times:
Traceback (most recent call last):
File "./sublime_plugin.py", line 62, in reload_plugin
File "./Package Control.py", line 9, in <module>
import urllib2
File "/home/tys/app/SublimeText2.2211/lib/python2.6/urllib2.py", line 94, in <module>
import httplib
File "/home/tys/app/SublimeText2.2211/lib/python2.6/httplib.py", line 78, in <module>
import mimetools
File "/home/tys/app/SublimeText2.2211/lib/python2.6/mimetools.py", line 6, in <module>
import tempfile
File "/home/tys/app/SublimeText2.2211/lib/python2.6/tempfile.py", line 34, in <module>
from random import Random as _Random
File "/home/tys/app/SublimeText2.2211/lib/python2.6/random.py", line 47, in <module>
from os import urandom as _urandom
ImportError: cannot import name urandom

This is a common error and the accepted solution is to re-build your virtual environment. (https://bugs.launchpad.net/ubuntu/+sour ... bug/954595)

However, you cannot rebuild the environment since the interpreter is compiled into sublime_text. I tried making a new virtualenv in the python install dir (using python2.6 offcourse) and I get the same error. Including the above libs in any other python (2.6, 2.7, virtualenv or not) does NOT give me this error.
So my guess is there is a discrepancy between the build in python2.6.2 and my system-wide python2.6.8.

What is the actual problem here? Can a decent virtualenv for sublime (not having the compiled in part) fix the issue? What is the appropriate fix? Currently I'm left with the choice of using the included zip file, disabling various plugins or using the system wide python, disabling the whole of python.

Its weird though that the problem actually arised in the new python2.7 version. Why is popping up in my python2.6 install?

Using: Debian, python2.6 (minimal)+python2.7 packages. Files in /usr/lib/python2.6/lib and /usr/lib/python2.7/lib differ.
knifter
 
Posts: 2
Joined: Tue Jul 03, 2012 9:35 am

Re: sublimes python2.6, no virtualenv, import urandom error

Postby knifter on Tue Jul 03, 2012 10:18 am

update:
I actually tried using pythonbrew. It compiles a whole new python (2.6) in ~/.pythonbrew. The compile failed and I dont really feel like fixing the issue. Especially since I suspect this newly compiled version to also be an up-to-date version, having the same issue. And, in the end, it's actually the same solution.

Second, it's seems bit weird to me to having to compile (and maintain) an additional python install in .pythonbrew.
knifter
 
Posts: 2
Joined: Tue Jul 03, 2012 9:35 am

Re: sublimes python2.6, no virtualenv, import urandom error

Postby dbabo on Tue Aug 21, 2012 2:53 am

i have the same issue(viewtopic.php?f=2&t=8763&p=35933#p35933) as knifter described.
would be interesting to hear from the tech support please?
dbabo
 
Posts: 25
Joined: Tue Jun 26, 2012 1:47 pm

Re: sublimes python2.6, no virtualenv, import urandom error

Postby jchadwick on Thu Dec 20, 2012 7:50 pm

Had the same problem here. I made a quick hack solution for it.

Code: Select all
# Hack to supply os.urandom
if not _exists("urandom"):
    def urandom(size=1):
        with file("/dev/urandom", 'rb') as f:
            return f.read(size)


Place this near the end of your os.py, just above

Code: Select all
import copy_reg as _copy_reg


and things should start working on next restart.
jchadwick
 
Posts: 2
Joined: Thu Dec 20, 2012 7:49 pm


Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot], movax, Orlmente, Yahoo [Bot] and 24 guests