c4rt1y

mac下使用notebook和虚拟目录

0x01 介绍

当前环境为python3环境,编写python文档,需要使用到notebook,这里记录下安装文档。

0x02 方案

# 1、安装 jupyter
brew install jupyter

# 2、进入启动项
echo 'export PATH="/Users/c4rt1y/Library/Python/3.9/bin:$PATH"' >> ~/.bash_profile

# 3、安装组件
pip install IPython
pip install notebook

# 4、启动[默认使用的是当前python环境]
jupyter notebook

# 若使用虚拟环境
## 创建python kernel,名称为python3
python -m ipykernel install --user --name 环境名称 --display-name "环境名称"
python -m ipykernel install --user --name python3 --display-name python3
## 修改notebook 的python版本[将python路径切换为虚拟目录的python文件即可]
cat ~/$HOME/Library/Jupyter/kernels/python3/kernel.json
{
 "argv": [
  "/Users/010sec/Documents/env/python3/bin/python",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ],
 "display_name": "basic",
 "language": "python"
}

## 移除虚拟环境
jupyter kernelspec remove 环境名称

0x03 资料来源

https://blog.csdn.net/weixin_40574958/article/details/79435081
GoTop