ipython/ipython — pull request #5022 by dongweiming (2014-02-04 11:28:59+00:00)
Title: Bugfix: OS X  ordinary users do not have permission to compile python stdlib's pyc, st_mtime do not change

When i use ipython autoreload on OS X 10.8.5, Sometimes can show the following error(In ubuntu it did not happen), For example:

```
In [1]: from lib2to3.refactor import get_all_fix_names

In [2]: lib2to3.fixes
[autoreload of lib2to3.fixer_util failed: Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/IPython/extensions/autoreload.py", line 233, in check
superreload(m, reload, self.old_objects)
ImportError: cannot import name token
]
[autoreload of lib2to3.pgen2.pgen failed: Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/IPython/extensions/autoreload.py", line 233, in check
superreload(m, reload, self.old_objects)
ImportError: cannot import name grammar
]
[autoreload of lib2to3.pgen2.driver failed: Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/IPython/extensions/autoreload.py", line 233, in check
superreload(m, reload, self.old_objects)
ImportError: cannot import name grammar
]
[autoreload of lib2to3.refactor failed: Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/IPython/extensions/autoreload.py", line 233, in check
superreload(m, reload, self.old_objects)
ImportError: cannot import name driver
]
[autoreload of lib2to3.btm_matcher failed: Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/IPython/extensions/autoreload.py", line 233, in check
superreload(m, reload, self.old_objects)
ImportError: cannot import name pytree
]
[autoreload of lib2to3.pgen2.parse failed: Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/IPython/extensions/autoreload.py", line 233, in check
superreload(m, reload, self.old_objects)
ImportError: cannot import name token
]
[autoreload of lib2to3.pgen2.tokenize failed: Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/IPython/extensions/autoreload.py", line 233, in check
superreload(m, reload, self.old_objects)
ImportError: cannot import name token
]
[autoreload of lib2to3.pgen2.grammar failed: Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/IPython/extensions/autoreload.py", line 233, in check
superreload(m, reload, self.old_objects)
ImportError: cannot import name token
]
[autoreload of lib2to3.btm_utils failed: Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/IPython/extensions/autoreload.py", line 233, in check
superreload(m, reload, self.old_objects)
ImportError: cannot import name pytree
]
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
in ()
----> 1 lib2to3.fixes

NameError: name 'lib2to3' is not defined
```

You can see some ImportErrors. At last, I found that because in osx, ordinary users call stdlib, no pyc compiled the module, Use `sys.modules.get` get more message：

```
# On OS X

# On Ubuntu

```
osx heen using .py:

```
ll /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib2to3/fixer_util.py*
-rw-r--r-- 1 root wheel 15K Feb 4 17:50 /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib2to3/fixer_util.py
-rw-r--r-- 1 root wheel 16K Feb 4 16:25 /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib2to3/fixer_util.pyc
-rw-r--r-- 1 root wheel 16K Jan 1 2012 /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib2to3/fixer_util.pyo
```
So `os.stat(py_filename).st_mtime > os.stat(pyc_filename).st_mtime`, I added a hack:

When has get the py_filename/pyc_filename's st_mtime, try to compile this py_name, if raise IOError with `Permission denied` then continue