V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
inv
V2EX  ›  Python

mac 环境下 Python 的中文支持?

  •  
  •   inv · Nov 21, 2015 · 6218 views
    This topic created in 3815 days ago, the information mentioned may be changed or developed.
    最近刚换了 mac ,但是在 mac 下写 Python 的时候发现这样一个问题。就算在代码首行加入#coding=utf-8 ,还是会报字符编码的错误,求解~~~
    11 replies    2015-11-24 18:01:29 +08:00
    meloncrashed
        1
    meloncrashed  
       Nov 22, 2015
    # -*- coding utf-8 -*-
    meloncrashed
        2
    meloncrashed  
       Nov 22, 2015
    # -*- coding: utf-8 -*-
    julyclyde
        3
    julyclyde  
       Nov 22, 2015
    lz 的编码看起来是正确的。你举个最小化例子让我看看到底是咋错的
    lwbjing
        4
    lwbjing  
       Nov 22, 2015
    2.7.6 同 #coding=utf-8 并没有问题啊...
    inv
        5
    inv  
    OP
       Nov 22, 2015
    @julyclyde
    类似于这样:
    #coding=utf-8
    #中文
    print "aa"
    会报这样的错误:
    File "/Users/inv/PycharmProjects/s_scan/test.py", line 3
    SyntaxError: Non-ASCII character '\xe4' in file /Users/inv/PycharmProjects/s_scan/test.py on line 3, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
    lixia625
        6
    lixia625  
       Nov 22, 2015 via Android
    快别折腾了 用 python3
    TaMud
        7
    TaMud  
       Nov 22, 2015
    mac os x ->python 2.6
    update!
    ntyangxd
        8
    ntyangxd  
       Nov 22, 2015 via iPhone
    文件格式也要 utf8
    inv
        9
    inv  
    OP
       Nov 22, 2015
    @TaMud 现在的 Python 版本是 2.7.10
    ericls
        10
    ericls  
       Nov 23, 2015
    你连一个例子也不给 别人怎么回答

    你是在 Python 里面 print('你好世界') 还是干了什么 导致了这个错误?
    julyclyde
        11
    julyclyde  
       Nov 24, 2015
    @inv 我觉得不太可能。你确定 coding=utf-8 这几个字的拼写没错吗?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2422 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 45ms · UTC 15:26 · PVG 23:26 · LAX 08:26 · JFK 11:26
    ♥ Do have faith in what you're doing.