LoginSignup
0
0

More than 1 year has passed since last update.

Pipenvを使って仮想環境を構築し、Jupyter Notebookを起動したい(Mac)

Last updated at Posted at 2023-05-14

はじめに

TensorFlowを使うための学習の一環で、画像分類機の作成に取り組みました。その際、講座ではjupyter notebookが簡単にinstallできる理由でAnacondaの利用を推奨していましたが、メインで使用しているPipenvでも同様のことをしたいと考えて、調べた結果を備忘録として残します。

手順

プロジェクトの制作

  1. Project用のdirectoryを作成する。
  2. 作成したdirectoryに移動する。
  3. pipenv install jupyter jupytext を実行して、Jupyter NotebookとJupytextが入ったPython環境を作成します。この際、自動でPipfileとPipfile.lockが作成されます。

設定情報の追加

~/.jupyter/jupyter_notebook_config.pyに設定情報を追加する必要があります。

  1. pipenv run jupyter notebook --generate-configを実行し~/.jupyter/jupyter_notebook_config.pyを作成します。
  2. ~/.jupyter/jupyter_notebook_config.pyをeditorで開き、以下のcodeを追加します。Jupytextが使用できるようになり、.ipynb.pyの変換が行えるようにします。
c.NotebookApp.contents_manager_class = "jupytext.TextFileContentsManager"
c.ContentsManager.default_jupytext_formats = "ipynb,py"

Jupyter Notebookの起動・停止

  1. pipenv run jupyter notebookを実行し、Jupyter Notebookを起動します。
    Screen Shot 2023-05-14 at 17.16.18.png
  2. Jupyter Notebookを起動しているterminalでCtrl+Cで停止します。

Jupyter Notebookが起動しない場合

  • ~/.jupyter/jupyter_notebook_config.pyを作成してechoで設定値を書き込みましたが、以下のerrorでJupyter Notebookが起動できませんでした。
Bad config encountered during initialization: The 'contents_manager_class' trait of a NotebookApp instance expected a subclass of notebook.services.contents.manager.ContentsManager or jupyter_server.contents.services.managers.ContentsManage, not the JupytextContentsManager JupytextContentsManager.
  • 設定値が適切に設定されているか確認したところ、getConfig()というFunctionを使用しているにもかかわらず、定義がされていなかったので簡易的に定義しました。
from traitlets.config import Config

def get_config():
    return Config()

#これだけ最初から含まれていた
c = get_config()

終わりに

今回初めて記事を書いてみましたが、物事を文章化することは非常に難しく時間のかかる作業であると再認識できました。定期的に備忘録を残していきたいと思っております。

参考文献

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0