安装jupyter notebook

起因

看一篇关于其他内容的教程贴,作者推荐的
看起来像ipython,调试、测试函数功能应该很方便,

安装

python3 -m pip install jupyter

启动

jupyter
command not found
搜索后发现好像win可以这么运行,但是macOS不行
通过python3 -m IPython notebook运行成功:
image.png

开始使用:

点击右上角的new-python3
image.png

设置默认文件存放位置 配置

python3 -m jupyter --config-dir查找配置文件位置:
image.png
使用vim打开配置文件,并加入一句话,来设置默认打开地址:
image.png
image.png
修改路径后,再打开,默认地址变成了配置的地址:/Desktop/jupyter_file
image.png

查看默认配置文件 新建自己的配置

!ipython profile locate default命令查看默认配置文件的位置

command not found ipython

参考
image.png
ipython指令通常找不到,因为python3中需要通过以下指令执行:
!python3 -m IPython profile locate default(python3中,调用modul需要通过python3 -m的形式)
如果还想用ipython指令,可以在.bash_profile文件中使用alias指令——即,在.bash_profile文件中加入下面一行:
alias ipython='python3 -m IPython'
修改后记得source ./.bash_profile
然后就可以直接在终端ipython了!解决

bash_profile重启终端会失效

参考

原因:

  • bash_profile中的内容只对当前窗口有效
  • 需要先source才能生效
  • ~~ ~~macOS默认使用的是zsh不是bash

解决办法:编辑~~~/.zshrc~~文件,加入~~source~~语句

  • ~~~/.zshrc~~文件好像是开机启动?有疑问

解决办法:把.bash_profile中的内容拷贝到.zshrc,如果没有就新建
image.png
再打开新的终端窗口,直接运行ipython,可行解决
image.png

jupyter: command not found解决

  • 查找jupyter在哪——终端find ~ -iname "jupyter"
  • image.png
  • 注意到bin(binary)通常是用来存放命令文件的,所以bin/jupyter应该是我们需要的那个jupyter
  • 把其所在的地址添加到环境变量:
    • 打开环境变量vim ~/.bash_profile
    • image.png
    • 添加一行:
    • image.png
    • 保存关闭,然后source ~/.bash_profile
  • 尝试:jupyter,不再是command not found
  • image.png