问题解决方案

1. Python 利用Matplotlib绘图时,无法显示中文字体的解决方案

根据网上的解决办法,先进行代码的设置:

python 复制代码
from matplotlib.font_manager import FontProperties

font = FontProperties(fname=" /SIMHEI.TTF")  # 替换为实际的字体文件路径
plt.rcParams['font.sans-serif'] = [font.get_name()]
plt.rcParams['axes.unicode_minus'] = False

如果设置的字体没有,则需要安装字体。

字体安装完成之后,还是报错,找不到字体,则需要:

python 复制代码
import matplotlib
print(matplotlib.matplotlib_fname())

运行代码,查找库的位置

虚拟环境当中可以:pip show 包名

找到对应的位置,进入ttf 目录:

/home/book/.local/lib/python3.5/site-packages/matplotlib/mpl-data/matplotlibrc/fonts/ttf

将安装的对应字体,复制一份到这目录下面

然后测试,如果还是不行,则清除缓存:

~/.cache/matplotlib/fontlist-v300.json(将文件删除)

删除之后重新启动对应的代码,即可

2. 虚拟环境安装(conda install)遇到:

Collecting package metadata (current_repodata.json): failed CondaSSLError: Encountered an SSL error. Most likely a certificate verification issue. Exception: HTTPSConnectionPool(host='repo.anaconda.com', port=443): Max retries exceeded with url: /pkgs/main/linux-64/current_repodata.json (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:997)')))

先运行conda config --show-sources查找.condarc文件文件,然后把文件的内容替换为以下内容即可:

python 复制代码
channels:
  - defaults
show_channel_urls: true
channel_alias: http://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
相关推荐
AI攻城狮3 小时前
用 Playwright 实现博客一键发布到稀土掘金
python·自动化运维
曲幽3 小时前
FastAPI分布式系统实战:拆解分布式系统中常见问题及解决方案
redis·python·fastapi·web·httpx·lock·asyncio
孟健18 小时前
Karpathy 用 200 行纯 Python 从零实现 GPT:代码逐行解析
python
码路飞20 小时前
写了个 AI 聊天页面,被 5 种流式格式折腾了一整天 😭
javascript·python
曲幽1 天前
FastAPI压力测试实战:Locust模拟真实用户并发及优化建议
python·fastapi·web·locust·asyncio·test·uvicorn·workers
敏编程1 天前
一天一个Python库:jsonschema - JSON 数据验证利器
python
前端付豪1 天前
LangChain记忆:通过Memory记住上次的对话细节
人工智能·python·langchain
databook1 天前
ManimCE v0.20.1 发布:LaTeX 渲染修复与动画稳定性提升
python·动效
花酒锄作田2 天前
使用 pkgutil 实现动态插件系统
python