Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

When I start qgis I get a python exception:

Couldn't load plugin fTools due an error when calling its classFactory() method
...
309, in _import
   mod = _builtin_import(name, globals, locals, fromlist, level)
 File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.py", line    47, in 
  from os import urandom as _urandom
ImportError: cannot import name urandom

From ImportError: cannot import name “urandom” [closed] it seems I would need to replace the python interpreter used by qgis but can't find a way to do that.

Any ideas on how to resolve / work around this?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

A little background: after lots of issues with OSX involving Python I did a clean install of the OS. Then Kyngchaos for QGIS, worked like a charm. Then tried to get Spyder, iPython, Pandas to run. No joy. Used MacPorts and after some pain in the posterior stuff it worked. QGIS didn't! Same error as Barak above. In Bash python running 2.7.3 In QGIS python running 2.7.1 Finally located the problem: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py and /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py not the same. The MacPorts (opt/local/...) missing last few lines of file. Copy these from the system version into the opt version and Bob's your uncle. And Spyder etc still work.

share|improve this answer

Thank you @mercergeoinfo! In my case

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py

was missing urandom, but

/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py

had urandom defined, and this was the only difference:

flengyel$ diff /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py \    
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py
740a741,759
> 
> 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):
>                 bs += read(_urandomfd, n - len(bs))
>         finally:
>             close(_urandomfd)
>         return bs

Other plugins with this dependency could be installed after copying the version from /System/Library to /Library:

sudo cp /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py \     
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py

NOTE: the question or the answer or both should refer to Mac OS X.

share|improve this answer

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.