Simplify IPython detection logic.

Close #1185.