#11344·ipython

IPython cannot handle emojis

Author: PythonCoderASCreated Sep 29, 2018Updated Sep 26, 2026
Labelswindows

Whenever I try to copy-paste any emoji into IPython, I always get this error:

In [13]: b'
Traceback (most recent call last):
  File "c:\program files (x86)\python37-32\lib\site-packages\IPython\lib\clipboard.py", line 18, in win32_clipboard_get
    import win32clipboard
ModuleNotFoundError: No module named 'win32clipboard'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\program files (x86)\python37-32\lib\site-packages\IPython\terminal\shortcuts.py", line 248, in win_paste
    text = win32_clipboard_get()
  File "c:\program files (x86)\python37-32\lib\site-packages\IPython\lib\clipboard.py", line 20, in win32_clipboard_get
    raise TryNext("Getting text from the clipboard requires the pywin32 "
IPython.core.error.TryNext: Getting text from the clipboard requires the pywin32 extensions: http://sourceforge.net/projects/pywin32/

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\program files (x86)\python37-32\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\program files (x86)\python37-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Program Files (x86)\Python37-32\Scripts\ipython.exe\__main__.py", line 9, in <module>
    sys.exit(start_ipython())
  File "c:\program files (x86)\python37-32\lib\site-packages\IPython\__init__.py", line 125, in start_ipython
    return launch_new_instance(argv=argv, **kwargs)
  File "c:\program files (x86)\python37-32\lib\site-packages\traitlets\config\application.py", line 658, in launch_instance
    app.start()
  File "c:\program files (x86)\python37-32\lib\site-packages\IPython\terminal\ipapp.py", line 356, in start
    self.shell.mainloop()
  File "c:\program files (x86)\python37-32\lib\site-packages\IPython\terminal\interactiveshell.py", line 485, in mainloop
    self.interact()
  File "c:\program files (x86)\python37-32\lib\site-packages\IPython\terminal\interactiveshell.py", line 468, in interact
    code = self.prompt_for_code()
  File "c:\program files (x86)\python37-32\lib\site-packages\IPython\terminal\interactiveshell.py", line 381, in prompt_for_code
    pre_run=self.pre_prompt, reset_current_buffer=True)
  File "c:\program files (x86)\python37-32\lib\site-packages\prompt_toolkit\interface.py", line 415, in run
    self.eventloop.run(self.input, self.create_eventloop_callbacks())
  File "c:\program files (x86)\python37-32\lib\site-packages\prompt_toolkit\eventloop\win32.py", line 81, in run
    callbacks.feed_key(k)
  File "c:\program files (x86)\python37-32\lib\site-packages\prompt_toolkit\interface.py", line 1048, in feed_key
    cli.input_processor.process_keys()
  File "c:\program files (x86)\python37-32\lib\site-packages\prompt_toolkit\key_binding\input_processor.py", line 219, in process_keys
    self._process_coroutine.send(key_press)
  File "c:\program files (x86)\python37-32\lib\site-packages\prompt_toolkit\key_binding\input_processor.py", line 176, in _process
    self._call_handler(matches[-1], key_sequence=buffer[:])
  File "c:\program files (x86)\python37-32\lib\site-packages\prompt_toolkit\key_binding\input_processor.py", line 247, in _call_handler
    handler.call(event)
  File "c:\program files (x86)\python37-32\lib\site-packages\prompt_toolkit\key_binding\registry.py", line 61, in call
    return self.handler(event)
  File "c:\program files (x86)\python37-32\lib\site-packages\IPython\terminal\shortcuts.py", line 251, in win_paste
    text = tkinter_clipboard_get()
  File "c:\program files (x86)\python37-32\lib\site-packages\IPython\lib\clipboard.py", line 61, in tkinter_clipboard_get
    text = root.clipboard_get()
  File "c:\program files (x86)\python37-32\lib\tkinter\__init__.py", line 804, in clipboard_get
    return self.tk.call(('clipboard', 'get') + self._options(kw))
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xed in position 23: invalid continuation byte

If you suspect this is an IPython bug, please report it at:
    https://github.com/ipython/ipython/issues
or send an email to the mailing list at [email protected]

You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.

Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
    %config Application.verbose_crash=True

Log from enabling config in magics:

bash
***************************************************************************

IPython post-mortem report

{'commit_hash': 'dd83a2163',
 'commit_source': 'installation',
 'default_encoding': 'utf-8',
 'ipython_path': 'c:\\program files '
                 '(x86)\\python37-32\\lib\\site-packages\\IPython',
 'ipython_version': '6.5.0',
 'os_name': 'nt',
 'platform': 'Windows-10-10.0.17134-SP0',
 'sys_executable': 'c:\\program files (x86)\\python37-32\\python.exe',
 'sys_platform': 'win32',
 'sys_version': '3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 '
                '32 bit (Intel)]'}

***************************************************************************



***************************************************************************

Crash traceback:

---------------------------------------------------------------------------
---------------------------------------------------------------------------
ModuleNotFoundErrorPython 3.7.0: c:\program files (x86)\python37-32\python.exe
                                                   Sat Sep 29 14:51:07 2018
A problem occurred executing Python code.  Here is the sequence of function
calls leading up to the error, with the most recent (innermost) call last.
c:\program files (x86)\python37-32\lib\site-packages\IPython\lib\clipboard.py in win32_clipboard_get()
     17     try:
---> 18         import win32clipboard
        win32clipboard = undefined
     19     except ImportError:

ModuleNotFoundError: No module named 'win32clipboard'

During handling of the above exception, another exception occurred:

---------------------------------------------------------------------------
TryNext         Python 3.7.0: c:\program files (x86)\python37-32\python.exe
                                                   Sat Sep 29 14:51:07 2018
A problem occurred executing Python code.  Here is the sequence of function
calls leading up to the error, with the most recent (innermost) call last.
c:\program files (x86)\python37-32\lib\site-packages\IPython\terminal\shortcuts.py in win_paste(event=KeyPressEvent(arg=1, key_sequence=[KeyPress(key=Key('<C-V>'), data='\x16')], is_repeat=False))
    247         try:
--> 248             text = win32_clipboard_get()
        text = undefined
        global win32_clipboard_get = <function win32_clipboard_get at 0x03439CD8>
    249         except TryNext:

c:\program files (x86)\python37-32\lib\site-packages\IPython\lib\clipboard.py in win32_clipboard_get()
     19     except ImportError:
---> 20         raise TryNext("Getting text from the clipboard requires the pywin32 "
        global TryNext = <class 'IPython.core.error.TryNext'>
     21                       "extensions: http://sourceforge.net/projects/pywin32/")

TryNext: Getting text from the clipboard requires the pywin32 extensions: http://sourceforge.net/projects/pywin32/

During handling of the above exception, another exception occurred:

---------------------------------------------------------------------------
UnicodeDecodeErrorPython 3.7.0: c:\program files (x86)\python37-32\python.exe
                                                   Sat Sep 29 14:51:07 2018
A problem occurred executing Python code.  Here is the sequence of function
calls leading up to the error, with the most recent (innermost) call last.
c:\program files (x86)\python37-32\lib\runpy.py in _run_module_as_main(mod_name='__main__', alter_argv=0)
    178            __loader__
    179            __package__
    180     """
    181     try:
    182         if alter_argv or mod_name != "__main__": # i.e. -m switch
    183             mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
    184         else:          # i.e. directory or zipfile execution
    185             mod_name, mod_spec, code = _get_main_module_details(_Error)
    186     except _Error as exc:
    187         msg = "%s: %s" % (sys.executable, exc)
    188         sys.exit(msg)
    189     main_globals = sys.modules["__main__"].__dict__
    190     if alter_argv:
    191         sys.argv[0] = mod_spec.origin
    192     return _run_code(code, main_globals, None,
--> 193                      "__main__", mod_spec)
        mod_spec = ModuleSpec(name='__main__', loader=<zipimporter object "C:\Program Files (x86)\Python37-32\Scripts\ipython.exe">, origin='C:\\Program Files (x86)\\Python37-32\\Scripts\\ipython.exe\\__main__.py')
    194 
    195 def run_module(mod_name, init_globals=None,
    196                run_name=None, alter_sys=False):
    197     """Execute a module's code without importing it
    198 
    199        Returns the resulting top level namespace dictionary
    200     """
    201     mod_name, mod_spec, code = _get_module_details(mod_name)
    202     if run_name is None:
    203         run_name = mod_name
    204     if alter_sys:
    205         return _run_module_code(code, init_globals, run_name, mod_spec)
    206     else:
    207         # Leave the sys module alone
    208         return _run_code(code, {}, init_globals, run_name, mod_spec)

c:\program files (x86)\python37-32\lib\runpy.py in _run_code(code=<code object <module> at 0x01008D30, file "C:\Pr...on37-32\Scripts\ipython.exe\__main__.py", line 2>, run_globals={'__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, '__cached__': r'C:\Program Files (x86)\Python37-32\Scripts\ipython.exe\__pycache__\__main__.cpython-37.pyc', '__doc__': None, '__file__': r'C:\Program Files (x86)\Python37-32\Scripts\ipython.exe\__main__.py', '__loader__': <zipimporter object "C:\Program Files (x86)\Python37-32\Scripts\ipython.exe">, '__name__': '__main__', '__package__': '', '__spec__': ModuleSpec(name='__main__', loader=<zipimporter ...\Python37-32\\Scripts\\ipython.exe\\__main__.py'), 're': <module 're' from 'c:\\program files (x86)\\python37-32\\lib\\re.py'>, ...}, init_globals=None, mod_name='__main__', mod_spec=ModuleSpec(name='__main__', loader=<zipimporter ...\Python37-32\\Scripts\\ipython.exe\\__main__.py'), pkg_name='', script_name=None)
     70         fname = script_name
     71         cached = None
     72     else:
     73         loader = mod_spec.loader
     74         fname = mod_spec.origin
     75         cached = mod_spec.cached
     76         if pkg_name is None:
     77             pkg_name = mod_spec.parent
     78     run_globals.update(__name__ = mod_name,
     79                        __file__ = fname,
     80                        __cached__ = cached,
     81                        __doc__ = None,
     82                        __loader__ = loader,
     83                        __package__ = pkg_name,
     84                        __spec__ = mod_spec)
---> 85     exec(code, run_globals)
        global exec = undefined
        code = <code object <module> at 0x01008D30, file "C:\Program Files (x86)\Python37-32\Scripts\ipython.exe\__main__.py", line 2>
        run_globals = {'__name__': '__main__', '__doc__': None, '__package__': '', '__loader__': <zipimporter object "C:\Program Files (x86)\Python37-32\Scripts\ipython.exe">, '__spec__': ModuleSpec(name='__main__', loader=<zipimporter object "C:\Program Files (x86)\Python37-32\Scripts\ipython.exe">, origin='C:\\Program Files (x86)\\Python37-32\\Scripts\\ipython.exe\\__main__.py'), '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, '__file__': 'C:\\Program Files (x86)\\Python37-32\\Scripts\\ipython.exe\\__main__.py', '__cached__': 'C:\\Program Files (x86)\\Python37-32\\Scripts\\ipython.exe\\__pycache__\\__main__.cpython-37.pyc', 're': <module 're' from 'c:\\program files (x86)\\python37-32\\lib\\re.py'>, 'sys': <module 'sys' (built-in)>, 'start_ipython': <function start_ipython at 0x035A9DB0>}
     86     return run_globals
     87 
     88 def _run_module_code(code, init_globals=None,
     89                     mod_name=None, mod_spec=None,
     90                     pkg_name=None, script_name=None):
     91     """Helper to run code in new namespace with sys modified"""
     92     fname = script_name if mod_spec is None else mod_spec.origin
     93     with _TempModule(mod_name) as temp_module, _ModifiedArgv0(fname):
     94         mod_globals = temp_module.module.__dict__
     95         _run_code(code, mod_globals, init_globals,
     96                   mod_name, mod_spec, pkg_name, script_name)
     97     # Copy the globals of the temporary module, as they
     98     # may be cleared when the temporary module goes away
     99     return mod_globals.copy()
    100 

C:\Program Files (x86)\Python37-32\Scripts\ipython.exe\__main__.py in <module>()
      1 # -*- coding: utf-8 -*-
      2 import re
      3 import sys
      4 
      5 from IPython import start_ipython
      6 
      7 if __name__ == '__main__':
      8     sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
----> 9     sys.exit(start_ipython())
        global sys.exit = <built-in function exit>
        global start_ipython = <function start_ipython at 0x035A9DB0>

c:\program files (x86)\python37-32\lib\site-packages\IPython\__init__.py in start_ipython(argv=None, **kwargs={})
    110     This is a public API method, and will survive implementation changes.
    111     
    112     Parameters
    113     ----------
    114     
    115     argv : list or None, optional
    116         If unspecified or None, IPython will parse command-line options from sys.argv.
    117         To prevent any command-line parsing, pass an empty list: `argv=[]`.
    118     user_ns : dict, optional
    119         specify this dictionary to initialize the IPython user namespace with particular values.
    120     kwargs : various, optional
    121         Any other kwargs will be passed to the Application constructor,
    122         such as `config`.
    123     """
    124     from IPython.terminal.ipapp import launch_new_instance
--> 125     return launch_new_instance(argv=argv, **kwargs)
        launch_new_instance = <bound method Application.launch_instance of <class 'IPython.terminal.ipapp.TerminalIPythonApp'>>
        argv = None
        kwargs = {}
    126 
    127 def start_kernel(argv=None, **kwargs):
    128     """Launch a normal IPython kernel instance (as opposed to embedded)
    129     
    130     `IPython.embed_kernel()` puts a shell in a particular calling scope,
    131     such as a function or method for debugging purposes,
    132     which is often not desirable.
    133     
    134     `start_kernel()` does full, regular IPython initialization,
    135     including loading startup files, configuration, etc.
    136     much of which is skipped by `embed()`.
    137     
    138     Parameters
    139     ----------
    140     

c:\program files (x86)\python37-32\lib\site-packages\traitlets\config\application.py in launch_instance(cls=<class 'IPython.terminal.ipapp.TerminalIPythonApp'>, argv=None, **kwargs={})
    643             lines.append(cls.class_config_section())
    644         return '\n'.join(lines)
    645 
    646     def exit(self, exit_status=0):
    647         self.log.debug("Exiting application: %s" % self.name)
    648         sys.exit(exit_status)
    649 
    650     @classmethod
    651     def launch_instance(cls, argv=None, **kwargs):
    652         """Launch a global instance of this Application
    653 
    654         If a global instance already exists, this reinitializes and starts it
    655         """
    656         app = cls.instance(**kwargs)
    657         app.initialize(argv)
--> 658         app.start()
        app.start = <bound method TerminalIPythonApp.start of <IPython.terminal.ipapp.TerminalIPythonApp object at 0x01027130>>
    659 
    660 #-----------------------------------------------------------------------------
    661 # utility functions, for convenience
    662 #-----------------------------------------------------------------------------
    663 
    664 def boolean_flag(name, configurable, set_help='', unset_help=''):
    665     """Helper for building basic --trait, --no-trait flags.
    666 
    667     Parameters
    668     ----------
    669 
    670     name : str
    671         The name of the flag.
    672     configurable : str
    673         The 'Class.trait' string of the trait to be set/unset with the flag

c:\program files (x86)\python37-32\lib\site-packages\IPython\terminal\ipapp.py in start(self=<IPython.terminal.ipapp.TerminalIPythonApp object>)
    341         if self.log_level <= logging.INFO: print()
    342 
    343     def _pylab_changed(self, name, old, new):
    344         """Replace --pylab='inline' with --pylab='auto'"""
    345         if new == 'inline':
    346             warnings.warn("'inline' not available as pylab backend, "
    347                       "using 'auto' instead.")
    348             self.pylab = 'auto'
    349 
    350     def start(self):
    351         if self.subapp is not None:
    352             return self.subapp.start()
    353         # perform any prexec steps:
    354         if self.interact:
    355             self.log.debug("Starting IPython's mainloop...")
--> 356             self.shell.mainloop()
        self.shell.mainloop = <bound method TerminalInteractiveShell.mainloop of <IPython.terminal.interactiveshell.TerminalInteractiveShell object at 0x00EFCD30>>
    357         else:
    358             self.log.debug("IPython not interactive...")
    359             if not self.shell.last_execution_succeeded:
    360                 sys.exit(1)
    361 
    362 def load_default_config(ipython_dir=None):
    363     """Load the default config file from the default ipython_dir.
    364 
    365     This is useful for embedded shells.
    366     """
    367     if ipython_dir is None:
    368         ipython_dir = get_ipython_dir()
    369 
    370     profile_dir = os.path.join(ipython_dir, 'profile_default')
    371     app = TerminalIPythonApp()

c:\program files (x86)\python37-32\lib\site-packages\IPython\terminal\interactiveshell.py in mainloop(self=<IPython.terminal.interactiveshell.TerminalInteractiveShell object>, display_banner=<object object>)
    470                 if (not self.confirm_exit) \
    471                         or self.ask_yes_no('Do you really want to exit ([y]/n)?','y','n'):
    472                     self.ask_exit()
    473 
    474             else:
    475                 if code:
    476                     self.run_cell(code, store_history=True)
    477 
    478     def mainloop(self, display_banner=DISPLAY_BANNER_DEPRECATED):
    479         # An extra layer of protection in case someone mashing Ctrl-C breaks
    480         # out of our internal code.
    481         if display_banner is not DISPLAY_BANNER_DEPRECATED:
    482             warn('mainloop `display_banner` argument is deprecated since IPython 5.0. Call `show_banner()` if needed.', DeprecationWarning, stacklevel=2)
    483         while True:
    484             try:
--> 485                 self.interact()
        self.interact = <bound method TerminalInteractiveShell.interact of <IPython.terminal.interactiveshell.TerminalInteractiveShell object at 0x00EFCD30>>
    486                 break
    487             except KeyboardInterrupt as e: