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
inv
V2EX  ›  Python

mac 环境下 Python 的中文支持?

  •  
  •   inv · 2015-11-21 22:07:58 +08:00 · 5356 次点击
    这是一个创建于 3081 天前的主题,其中的信息可能已经有所发展或是发生改变。
    最近刚换了 mac ,但是在 mac 下写 Python 的时候发现这样一个问题。就算在代码首行加入#coding=utf-8 ,还是会报字符编码的错误,求解~~~
    11 条回复    2015-11-24 18:01:29 +08:00
    meloncrashed
        1
    meloncrashed  
       2015-11-22 00:44:38 +08:00
    # -*- coding utf-8 -*-
    meloncrashed
        2
    meloncrashed  
       2015-11-22 00:45:24 +08:00
    # -*- coding: utf-8 -*-
    julyclyde
        3
    julyclyde  
       2015-11-22 10:20:40 +08:00
    lz 的编码看起来是正确的。你举个最小化例子让我看看到底是咋错的
    lwbjing
        4
    lwbjing  
       2015-11-22 10:48:03 +08:00
    2.7.6 同 #coding=utf-8 并没有问题啊...
    inv
        5
    inv  
    OP
       2015-11-22 11:40:30 +08:00
    @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  
       2015-11-22 13:01:39 +08:00 via Android
    快别折腾了 用 python3
    TaMud
        7
    TaMud  
       2015-11-22 14:57:13 +08:00
    mac os x ->python 2.6
    update!
    ntyangxd
        8
    ntyangxd  
       2015-11-22 17:16:12 +08:00 via iPhone
    文件格式也要 utf8
    inv
        9
    inv  
    OP
       2015-11-22 19:46:59 +08:00
    @TaMud 现在的 Python 版本是 2.7.10
    ericls
        10
    ericls  
       2015-11-23 04:45:31 +08:00
    你连一个例子也不给 别人怎么回答

    你是在 Python 里面 print('你好世界') 还是干了什么 导致了这个错误?
    julyclyde
        11
    julyclyde  
       2015-11-24 18:01:29 +08:00
    @inv 我觉得不太可能。你确定 coding=utf-8 这几个字的拼写没错吗?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1115 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 18:28 · PVG 02:28 · LAX 11:28 · JFK 14:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.