PyCharm控制台中文乱码

PyCharm 控制台中文乱码通常由编码设置问题引起。以下是解决方法:

1. 检查项目编码

  1. 打开 File > Settings (Windows/Linux) 或 PyCharm > Preferences (macOS)。

  2. 导航到 Editor > File Encodings

  3. 确保 Global EncodingProject EncodingDefault encoding for properties files 都设置为 UTF-8

2. 修改运行配置

  1. 打开 Run > Edit Configurations

  2. 选择你的运行配置。

  3. Configuration 选项卡中,找到 Environment variables ,添加 PYTHONIOENCODING=utf-8

3. 修改控制台编码

  1. 打开 Help > Edit Custom VM Options

  2. 添加 -Dfile.encoding=UTF-8

  3. 重启 PyCharm。

4. 修改系统环境变量(Windows)

  1. 打开系统环境变量设置。

  2. 添加或修改 PYTHONIOENCODINGutf-8

5. 代码中设置编码

在 Python 文件开头添加:

复制代码
import sys
import io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')

6. 检查终端编码

确保系统终端或命令行工具的编码也是 UTF-8。

7. 更新 PyCharm

确保使用的是最新版本,旧版本可能存在编码问题。

通过这些步骤,通常可以解决 PyCharm 控制台中文乱码问题。

相关推荐
阿尔的代码屋37 分钟前
[大模型实战 07] 基于 LlamaIndex ReAct 框架手搓全自动博客监控 Agent
人工智能·python
AI探索者18 小时前
LangGraph StateGraph 实战:状态机聊天机器人构建指南
python
AI探索者18 小时前
LangGraph 入门:构建带记忆功能的天气查询 Agent
python
FishCoderh20 小时前
Python自动化办公实战:批量重命名文件,告别手动操作
python
躺平大鹅20 小时前
Python函数入门详解(定义+调用+参数)
python
曲幽21 小时前
我用FastAPI接ollama大模型,差点被asyncio整崩溃(附对话窗口实战)
python·fastapi·web·async·httpx·asyncio·ollama
两万五千个小时1 天前
落地实现 Anthropic Multi-Agent Research System
人工智能·python·架构
哈里谢顿1 天前
Python 高并发服务限流终极方案:从原理到生产落地(2026 实战指南)
python
用户8356290780512 天前
无需 Office:Python 批量转换 PPT 为图片
后端·python
markfeng82 天前
Python+Django+H5+MySQL项目搭建
python·django