diff --git a/IPython/utils/module_paths.py b/IPython/utils/module_paths.py
index d50df80..0570c32 100644
--- a/IPython/utils/module_paths.py
+++ b/IPython/utils/module_paths.py
@@ -64,7 +64,7 @@ def find_mod(module_name):
         return None
     else:
         split_path = module_path.split(".")
-        if split_path[1] in ["py", "pyw"]:
+        if split_path[-1] in ["py", "pyw"]:
             return module_path
         else:
             return None