推荐学习书目
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 · Mar 31, 2017 · 2277 views
    This topic created in 3333 days ago, the information mentioned may be changed or developed.

    代码:

    '''

    -- 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 replies    2017-03-31 00:27:46 +08:00
    billlee
        1
    billlee  
       Mar 31, 2017
    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
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2933 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 85ms · UTC 09:46 · PVG 17:46 · LAX 02:46 · JFK 05:46
    ♥ Do have faith in what you're doing.