如何获取matplotlib的安装目录及相关系统路径信息?
- 内容介绍
- 文章标签
- 相关推荐
本文共计358个文字,预计阅读时间需要2分钟。
1. 安装matplotlib并获取其安装位置:pythonimport matplotlibprint(matplotlib.__version__)print(matplotlib.__file__)
一、获取matplotlib的安装位置
导入matplotlib,打印__file__属性,即可显示matplotlib包的安装位置。
In [1]: import matplotlib In [2]: matplotlib.__version__ Out[2]: '3.3.2' In [3]: matplotlib.__file__ Out[3]: 'd:\\ProgramData\\Anaconda3\\lib\\site-packages\\matplotlib\\__init__.py
二、获取matplotlib的配置目录
配置目录获取比较复杂,遵循以下规律:
如果设置了MPLCONFIGDIR 环境变量,那么配置目录就是该变量对应目录。如果没有选择,那么配置目录为$HOME/.matplotlib。
In [4]: matplotlib.get_configdir() Out[4]: 'C:\\Users\\adminstrator\\.matplotlib'
三、获取matplotlib的缓存目录
一般情况下,get_cachedir()和get_configdir()返回同一个目录,特例是在linux中,如果设置环境变量$XDG_CACHE_HOME/$HOME/.cache,则使用环境变量设置的目录。
matplotlib的字体缓存存放在该目录。
本文共计358个文字,预计阅读时间需要2分钟。
1. 安装matplotlib并获取其安装位置:pythonimport matplotlibprint(matplotlib.__version__)print(matplotlib.__file__)
一、获取matplotlib的安装位置
导入matplotlib,打印__file__属性,即可显示matplotlib包的安装位置。
In [1]: import matplotlib In [2]: matplotlib.__version__ Out[2]: '3.3.2' In [3]: matplotlib.__file__ Out[3]: 'd:\\ProgramData\\Anaconda3\\lib\\site-packages\\matplotlib\\__init__.py
二、获取matplotlib的配置目录
配置目录获取比较复杂,遵循以下规律:
如果设置了MPLCONFIGDIR 环境变量,那么配置目录就是该变量对应目录。如果没有选择,那么配置目录为$HOME/.matplotlib。
In [4]: matplotlib.get_configdir() Out[4]: 'C:\\Users\\adminstrator\\.matplotlib'
三、获取matplotlib的缓存目录
一般情况下,get_cachedir()和get_configdir()返回同一个目录,特例是在linux中,如果设置环境变量$XDG_CACHE_HOME/$HOME/.cache,则使用环境变量设置的目录。
matplotlib的字体缓存存放在该目录。

