MacBook Air M2 安装jupyter、pandas、numpy、matplotlib、openpyx、mysql-connector-python

719 阅读1分钟

使用 Homebrew 安装的 Python 来创建虚拟环境:

# 创建虚拟环境
/opt/homebrew/bin/python3 -m venv myenv

# 激活虚拟环境
source myenv/bin/activate

在虚拟环境中安装包

一旦虚拟环境被激活,你就可以在其中安装任何你需要的包,包括 pandas,而不影响系统级别的 Python 环境或其他虚拟环境。

在虚拟环境中安装 jupyter、pandas、numpy、matplotlib、openpyxl等包/库。从pypi.tuna.tsinghua.edu.cn/simple 清华大学开源软件镜像站中下载,提高下载速度。

# 安装jupyter
pip3 install jupyter -i https://pypi.tuna.tsinghua.edu.cn/simple 

# 安装pandas(用于数据清洗)
pip3 install pandas -i https://pypi.tuna.tsinghua.edu.cn/simple  

# 安装numpy
pip3 install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple 

# 安装matplotlib(用于绘制可视化图表)
pip3 install matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple 

# 安装openpyxl(用于读写文件)
pip3 install openpyxl -i https://pypi.tuna.tsinghua.edu.cn/simple

#安装mysql-connector-python(用于连接mysql的)
pip3 install mysql-connector-python -i https://pypi.tuna.tsinghua.edu.cn/simple

启动Jupyter notebook(因为jupyter是安装在虚拟环境中,所以每次使用该虚拟环境之前激活虚拟环境):

# 激活虚拟环境
source myenv/bin/activate

# 启动虚拟环境
jupyter notebook

这将启动Jupyter notebook服务器,并在默认的浏览器中打开Jupyter的界面,或者你可以复制终端中显示的URL,在浏览器中手动打开。

在 Notebook 中输入以下代码来测试 pandas 是否已正确安装和使用:

import pandas as pd
print(pd.__version__)