环境:macOS
按照以下步骤进行操作:
1. 打开终端
- 通过“应用程序”文件夹中的“实用工具”文件夹找到“终端”应用程序
2. 安装matplotlib
- 如果matplotlib尚未在你的环境中安装,你可以使用以下命令来安装它(这里我使用的是conda):
conda install matplotlib
- 或者,如果你更倾向于使用pip来安装,你也可以尝试:
pip install matplotlib
3. 启动Jupyter Notebook
- 在Conda环境激活的状态下,启动Jupyter Notebook。使用以下命令来启动它:
jupyter notebook
将会在默认Web浏览器中打开一个新的Jupyter Notebook界面。
4. 检查环境
-
在Jupyter Notebook中,通过运行以下代码来检查当前使用的Python环境及其安装的包:
import sys print(sys.executable) import pkg_resources installed_packages = pkg_resources.working_set installed_packages_list = sorted(["%s==%s" % (i.key, i.version) for i in installed_packages]) print(installed_packages_list)
运行后,会显示你当前Python环境的路径以及已安装的所有包的列表。应该能在列表中看到
matplotlib
。
5. 使用matplotlib
-
此时,导入matplotlib包,则不会提示不存在相关的包,可以在Jupyter Notebook中无障碍地导入和使用了:
import matplotlib.pyplot as plt # 使用matplotlib的代码