gh-7053: check for OSError during rehashx()

Fix for https://github.com/ipython/ipython/issues/7053
wouldn't `path = filter(lambda x:os.access(x, os.X_OK), path)` also work and avoid a lot of failed chdir and failed exceptions?