V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
cstome
V2EX  ›  Python

Python 在英文版 Windows 系统下显示中文报错该怎么解决?

  •  
  •   cstome · 2017-03-31 00:23:41 +08:00 · 1808 次点击
    这是一个创建于 2789 天前的主题,其中的信息可能已经有所发展或是发生改变。

    代码:

    '''

    -- coding: utf-8 --

    print('中文') '''

    报错:

    ''' File "C:\Users\Cstome\AppData\Local\Programs\Python\Python35\lib\encodings\cp437.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_map)[0] UnicodeEncodeError: 'charmap' codec can't encode characters in position 85-90: character maps to <undefined> '''

    local 切换成简体中文就好了,但除此之外还有其他方法吗?

    1 条回复    2017-03-31 00:27:46 +08:00
    billlee
        1
    billlee  
       2017-03-31 00:27:46 +08:00
    The character encoding is platform-dependent. Under Windows, if the stream is interactive (that is, if its isatty() method returns True), the console codepage is used, otherwise the ANSI code page. Under other platforms, the locale encoding is used (see locale.getpreferredencoding()).

    Under all platforms though, you can override this value by setting the PYTHONIOENCODING environment variable before starting Python.

    所以,试试启动 python 前 chcp 65001
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5526 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 07:43 · PVG 15:43 · LAX 23:43 · JFK 02:43
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.