12

I have an utf-8 encoded file cjk.py:

print("打印")

Unsurprisingly, running python cjk.py yields

Traceback (most recent call last):
  File "cjk.py", line 1, in <module>
    print('\u6253\u5370')
  File "C:\Python33\lib\encodings\cp850.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-1: character maps to <undefined>

Yet running idle -r cjk.py works perfectly:

打印

Can I configure notepad++'s NppExec plugin to behave like Idle? I've trying setting input and output encoding to UTF-8, to no avail (same exception as when running python cjk.py from the console)

Clément
  • 12,299
  • 15
  • 75
  • 115
  • Hi, I am encountering the same problem myself. Have you found a solution to your problem? – 5xum Jul 02 '14 at 09:04
  • @Clément I don't see the same problem, rather it prints the content `打印`. I have used this line `#coding=utf-8` at the top of the program. What python version are you using? – RAM Aug 09 '14 at 16:17
  • You don't specify which version of Python and which localisation and which version of which OS you are using. I will guess that it is Python 3.3 and some version of Windows, perhaps Windows 7, localised for French as used in France. Am I someone correct? – Jim DeLaHunt Sep 07 '14 at 04:03
  • Indeed; French or France, Windows 8, and Python 3.3 – Clément Sep 07 '14 at 18:42

1 Answers1

4

I had the same problem and fixed it.

Add env_set PYTHONIOENCODING=utf-8 just below C:\Python27\python.exe "$(FULL_CURRENT_PATH)" in the dialog box when you press F6.

Worked like a charm for me, hope it helps.

Source: http://sourceforge.net/p/npp-plugins/discussion/672146/thread/d94ff609/

HedonNNN
  • 51
  • 6
  • 1
    Note that you also need to update the NppExec Console Output... option to be UTF-8, otherwise characters don't print correctly. – yoyo Aug 28 '15 at 23:37
  • 1
    thank you @yoyo! On Notepad++ 8.4.8 one must go to Plugin menu > NppExec >"Console Output..." > tick UTF-8. Et voila, problème résolu. – WobblyWindows Mar 04 '23 at 19:22