[問題解決] jupyter notebook報錯: zsh: command not found; bad interpreter; Error executing Jupyter command 'notebook'


jupyter notebook報錯: zsh: command not found; bad interpreter; Error executing Jupyter command 'notebook'

問題描述

系統

macOS Catalina 10.15.7 (我認為大部分linux版本是適用此種解決方法的,windows不知道)

背景

我一般都是在terminal里直接跑python,為什么不用anaconda啥的主要怕麻煩。 但是這樣的話,我在使用pip3 install jupyter --user 以及 pip3 install IPython --user之后無法在terminal 里直接

jupyter notebook

去呼出notebook。報的錯是 zsh: command not found

添加路徑

首先,macOS Catalina 終端已經改成了zsh,所以我們需要將jupyter的路徑添加到PATH里。

pip3 show Jupyter

Name: jupyter
Version: 1.0.0
Summary: Jupyter metapackage. Install all the Jupyter components in one go.
Home-page: http://jupyter.org
Author: Jupyter Development Team
Author-email: jupyter@googlegroups.org
License: BSD
Location: /Users/xxx/Library/Python/3.8/lib/python/site-packages
Requires: jupyter-console, notebook, qtconsole, ipywidgets, ipykernel, nbconvert
Required-by:

可以發現location為/Users/xxx/Library/Python/3.8/lib/python/site-packages

vi ~/.zshrc

添加這么一句

export PATH="/Users/xxx/Library/Python/3.8/bin:$PATH"

然后重載命令

source .zshrc

修改指定的python版本

然而,這樣修改完之后,我試圖jupyter notebook,又出現了新的問題

zsh: /Users/xxx/Library/Python/3.8/bin/jupyter: bad interpreter: /applications/xcode.app/contents/developer/usr/bin/python3: no such file or directory

發現他說這個interpreter是找不到了,我一看,是我之前安裝的xcode里的python3環境,不過我已經卸載了。 我就希望能夠指定python版本,也就是/usr/bin/python3去運行jupyter。 經過一段時間的摸索,發現他指定python版本的方法是在文件的頭部指定了路徑,所以我們先修改一下jupyter文件,

vi /Users/xxx/Library/Python/3.8/bin/jupyter

把第一行改成了#!/usr/bin/python3

然后繼續jupyter notebook 還是不work,報的錯為

Error executing Jupyter command 'notebook': [Errno 2] No such file or directory

我感覺這個錯誤在於它本來是把jupyter notebook翻譯成jupyter-notebook 在執行,我們可以修改jupyter-notebook后再執行一下

vi /Users/xxx/Library/Python/3.8/bin/jupyter-notebook

把第一行改成了#!/usr/bin/python3
然后jupyter notebook

成功呼出。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM