2

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

unor
  • 1,250
  • 2
  • 16
  • 31
Nx212
  • 53
  • 4

1 Answers1

1

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

Anthon
  • 78,313
  • 42
  • 165
  • 222
  • 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 "", line 1, in 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
  • Which version of 2.6 did you install ( I have been looking at 2.6, self-compiled, running under Ubuntu 8.04 ). – Anthon Apr 19 '13 at 16:51
  • python-2.6.5-2.5mdv2010.2.x86_64 – Nx212 Apr 19 '13 at 16:58
  • That is definitely in the 2.6.5 source distribution, so mandriva took it out (also reported [here](https://answers.launchpad.net/hplip/+question/201039)). Looks like that mandriva version does not have `/dev/urandom` for some reason. – Anthon Apr 19 '13 at 17:08
  • But I found that `urandom` exists in the directory `/dev` – Nx212 Apr 19 '13 at 17:23
  • I get offers to move this discussion to chat, but unfortunately you have not enough reputation to be able write there. I added the lines from the source distribution, can you add those to your os.py? – Anthon Apr 19 '13 at 17:36