徹底卸載uninstall jupyter notebook不完全與"The jupyter" distribution was not found問題

在使用 pip uninstall jupyter 或 conda uninstall jupyter 後,經常會發現jupyter notebook仍未被完全卸載,原因是pip在uninstall jupyter時只卸載了jupyter的部分包。

完全卸載jupyter notebook可採用:

pip install pip-autoremove
pip-auto remove jupyter -y

即可完整刪除jupyter

它實際上刪除了以下各相關的庫,如果其中有其他庫所依賴的庫,可以手動卸載不需要的。

pip uninstall jupyter
pip uninstall jupyter_core
pip uninstall jupyter-client
pip uninstall jupyter-console
pip uninstall notebook
pip uninstall qtconsole
pip uninstall nbconvert
pip uninstall nbformat

自行注意切換pip/pip3。

 

如果在卸載jupyter時報錯,"The jupyter" distribution was not found,但在命令行中輸入jupyter仍然存在的情況,是因爲系統中裝了多個jupyter notebook導致的。這個問題似乎比較罕見,csdn/stack overflow上也沒幾個討論的,今天恰好遇到這個error並解決了,在此分享一下解決辦法。

問題的關鍵在於可能在多個python/pip環境下安裝了多個版本的jupyter,在執行pip uninstall的時候,卸載的只有本版本pip安裝的jupyter而已。使用pip的版本可以用 which pip 查看,可以用which -a pip查看安裝於本機的所有pip。

因此,我們只要用which -a jupyter就可以看到本機安裝的所有版本的jupyter,然後對應一一卸載。大多數情況下jupyter和pip的文件路徑是一樣的,因此使用該目錄的pip對其卸載即可。
如,假設我們看到一個jupyter的path是/usr/local/bin/jupyter,就可以使用下方命令對其進行卸載:

/usr/local/bin/pip uninstall jupyter

當然你可以ls該目錄查看所有jupyter相關的庫,然後使用上方的手動卸載方式一一卸載。

當然有可能你安裝的是snap下的jupyter,如果你看到有一個jupyter是存在於類似於/usr/bin/snap目錄下的話。
對於snap安裝的jupyter,使用snap remove jupyter即可卸載。

刪掉所有版本的jupyter,jupyter notebook就被徹底刪除了,接下來使用pip install jupyter即可重新安裝,當然建議在裝之前,pip install -U pip 更新一下pip

最後,說一下這個error可能的原因,個人分析是在anaconda環境下安裝jupyter notebook時,使用sudo apt install jupyter-core或sudo snap install jupyter導致的,因此注意在anaconda下,儘可能使用conda install jupyter或pip install jupyter來進行jupyter notebook的安裝。

 

發佈了9 篇原創文章 · 獲贊 2 · 訪問量 1354
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章