Fix builtins import in Python3

This commit is contained in:
Thomas Pointhuber 2018-08-13 20:42:08 +02:00 committed by Maciej Suminski
parent f316b98f45
commit 0812f71bd3
2 changed files with 12 additions and 2 deletions

View File

@ -63,8 +63,12 @@ class PcbnewPyShell(editor.EditorNotebookFrame):
intro = 'Py %s' % version.VERSION
import imp
module = imp.new_module('__main__')
import __builtin__
module.__dict__['__builtins__'] = __builtin__
if sys.version_info >= (3,):
import builtins
module.__dict__['__builtins__'] = builtins
else:
import __builtin__
module.__dict__['__builtins__'] = __builtin__
namespace = module.__dict__.copy()
self.config_dir = pcbnew.GetKicadConfigPath()

View File

@ -338,7 +338,13 @@ wxWindow* CreatePythonShellWindow( wxWindow* parent, const wxString& aFramenameI
// executed. Put a reference to the builtins module in it.
PyObject* globals = PyDict_New();
#if PY_MAJOR_VERSION >= 3
PyObject* builtins = PyImport_ImportModule( "builtins" );
#else
PyObject* builtins = PyImport_ImportModule( "__builtin__" );
#endif
wxASSERT( builtins );
PyDict_SetItemString( globals, "__builtins__", builtins );
Py_DECREF( builtins );