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?

3 Answers 3


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.


I got this error and unable to load "Processing" plugin. I visited many sites but didn't find satisfactory answer. The method worked for me is :

  • Start QGIS.
  • Error message will appear. Cut it and let qgis start.
  • Go to Manage plugin
  • Look at Red color Plugins or those need upgrading/downgrading
  • Do the needful and it will work again

Thank you @mercergeoinfo! In my case


was missing urandom, but


had urandom defined, and this was the only difference:

flengyel$ diff /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py \    
> 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 \     

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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