diff --git a/IPython/core/shellapp.py b/IPython/core/shellapp.py index 6406ea4..9398518 100644 --- a/IPython/core/shellapp.py +++ b/IPython/core/shellapp.py @@ -302,4 +302,12 @@ class InteractiveShellApp(Configurable): def _run_module(self): """Run module specified at the command-line.""" if self.module_to_run: - self.shell.safe_run_module(self.module_to_run, self.shell.user_ns) + # Make sure that the module gets a proper sys.argv as if it were + # run using `python -m`. + save_argv = sys.argv + sys.argv = [sys.executable] + self.extra_args + try: + self.shell.safe_run_module(self.module_to_run, + self.shell.user_ns) + finally: + sys.argv = save_argv