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

centos6.8 系统编码和 Python 文件的编码问题

  •  
  •   littlepython · 2019-08-24 15:50:42 +08:00 · 1594 次点击
    这是一个创建于 1704 天前的主题,其中的信息可能已经有所发展或是发生改变。
    每次登录显示这种问题
    -bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
    -bash: ulimit: open files: cannot modify limit: Operation not permitted

    然后运行 python 文件 打印中文日志就会出现
    UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-4: ordinal not in range(128)

    这种该怎么设置正常呀 用 python 打印出来的系统编码是 ANSI 这种
    3 条回复    2019-08-25 13:46:38 +08:00
    hangvane
        1
    hangvane  
       2019-08-24 18:35:58 +08:00   ❤️ 1
    试试这条?我用来解决 docker 容器中无法正常显示中文的问题
    echo "export LANG=C.UTF-8" >>/etc/profile
    littlepython
        2
    littlepython  
    OP
       2019-08-24 19:56:07 +08:00
    @hangvane 好像不行
    tempdban
        3
    tempdban  
       2019-08-25 13:46:38 +08:00 via Android
    你是不是自己换过 libc
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3578 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 87ms · UTC 11:03 · PVG 19:03 · LAX 04:03 · JFK 07:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.