Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

When I try to open Gajim using terminal on gnome I get the following:

Traceback (most recent call last):
  File "gajim.py", line 106, in <module>
    import common.configpaths
  File "/usr/share/gajim/src/common/configpaths.py", line 27, in <module>
    import tempfile
  File "/usr/lib64/python2.6/tempfile.py", line 34, in <module>
    from random import Random as _Random
  File "/usr/lib64/python2.6/random.py", line 47, in <module>
    from os import urandom as _urandom
ImportError: cannot import name urandom

Any idea how to fix this?

My OS is Mandriva 2010.1, Python is v2.6 upgraded from v2.4

share|improve this question
    
Can you include more details about your OS (distribution, version) and the version of python on your machine to help in solving the problem? –  Bichoy Apr 19 '13 at 15:42
    
My OS is Mandriva 2010.1, Python is v2.6 upgraded from v2.4 –  Nx212 Apr 19 '13 at 15:51
3  
Better add add it to the question –  Bichoy Apr 19 '13 at 15:53
    
@Bichoy thx for the advice –  Nx212 Apr 19 '13 at 15:55

1 Answer 1

up vote 1 down vote accepted

You are probably importing the wrong os.py module. Try starting python2.6 and then

>>> import os
>>> print os.__file__

That should be /usr/lib64/python2.6/os.py or /usr/lib64/python2.6/os.pyc. If it is not remove (or rename) the file that you found. If it is try:

>>> os.urandom(3)

This should give you a string of 3 characters. If it does, then gajim is finding the wrong os.py module. If you get the same error as when running gajim then look in the /usr/lib64/python2.6/os.py at the end urandom should be defined if it does not exist ( using the line if not _exists("urandom":).

If it is not defined, as seems to be the case for python-2.6.5-2.5mdv2010.2.x86_64, and /dev/urandom exists you could try to re-add the code:

if not _exists("urandom"):
    def urandom(n):
        """urandom(n) -> str

        Return a string of n random bytes suitable for cryptographic use.

        """
        try:
            _urandomfd = open("/dev/urandom", O_RDONLY)
        except (OSError, IOError):
            raise NotImplementedError("/dev/urandom (or equivalent) not found")
        try:
            bs = b""
            while n - len(bs) >= 1:
                bs += read(_urandomfd, n - len(bs))
        finally:
            close(_urandomfd)
        return bs

See also: this bug report

share|improve this answer
    
I got: /usr/lib64/python2.6/os.pyc –  Nx212 Apr 19 '13 at 16:11
    
I updated the things to test in the answer. –  Anthon Apr 19 '13 at 16:20
    
>>> os.urandom(3) got me this: >>> os.urandom(3) Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'module' object has no attribute 'urandom' >>> –  Nx212 Apr 19 '13 at 16:33
    
can you look at the last 20 lines or so of /usr/lib64/python2.6/os.py? That should have the if statement in there. –  Anthon Apr 19 '13 at 16:38
    
I'm afraid I can't find if not _exists("urandom":) in os.py –  Nx212 Apr 19 '13 at 16:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.