diff --git a/modules/gui/src/python_shell/main_thread_runner.cc b/modules/gui/src/python_shell/main_thread_runner.cc
index 6b05ca64a78f9b3924fc5b0bf7e6c11d813dd442..4dcb382da80c5fc4599b55cacc2b31cce619aab6 100644
--- a/modules/gui/src/python_shell/main_thread_runner.cc
+++ b/modules/gui/src/python_shell/main_thread_runner.cc
@@ -37,7 +37,8 @@ void MainThreadRunner::Run(const QString& widget)
   PyGILState_STATE gstate = PyGILState_Ensure();
   bp::object  main_module = bp::import("__main__");
   bp::object main_namespace = main_module.attr("__dict__");
-  bp::exec(bp::str("Proxy._widget_=QtGui."+widget.toStdString()+"()\n"),main_namespace,main_namespace);
+  std::string cmd = "Proxy._widget_=QtGui." + widget.toStdString() + "()\n";
+  bp::exec(cmd.c_str(), main_namespace, main_namespace);
   PyGILState_Release(gstate);
 }
 
diff --git a/modules/gui/src/python_shell/python_interpreter_worker.cc b/modules/gui/src/python_shell/python_interpreter_worker.cc
index e75f484600f3b749756042783316ece6697991fb..ed1dea231fe219d450cd4c6a4adc718661eaad4d 100644
--- a/modules/gui/src/python_shell/python_interpreter_worker.cc
+++ b/modules/gui/src/python_shell/python_interpreter_worker.cc
@@ -126,7 +126,7 @@ void PythonInterpreterWorker::run_command_(std::pair<unsigned int,QString> pair)
         handle_redirector_output(QString::fromStdString(rstring)+"\n");
       }
     } else {
-      bp::exec(bp::str(command.toStdString()),main_namespace_,main_namespace_);
+      bp::exec(command.toStdString().c_str(), main_namespace_, main_namespace_);
     }
     output_redirector_->Flush();
     error_redirector_->Flush();