LoginSignup
8
5

More than 3 years have passed since last update.

pythonの環境をpipenvで構築してjupyter notebookを使ってみた(Mac)

Last updated at Posted at 2019-05-09

前提

  • homebrewがインストールされていること
  • Xcode Command Line Toolsがインストールされていること

install pipenv

pythonでのnpmのような管理ツール
brewからinstall

brew install pipenv

gitへのcommit

Pipfile(とPipfile.lock)をコミットに含める
npmでのpackage.jsonやpackage-lock.jsonのようなものです

jupyter notebook

work ディレクトリを作成しjupyterとjupytextをinstall

mkdir <directory_name>
cd <directory_name>
pipenv install jupyter jupytext

初回のみ行う手順

  • pipenv run jupyter notebook --generate-configコマンドを実行し、~/.jupyter/jupyter_notebook_config.pyを作成します。

  • echo 'c.NotebookApp.contents_manager_class = "jupytext.TextFileContentsManager"' >> ~/.jupyter/jupyter_notebook_config.pyコマンドを実行し、Jupytextを利用可能にします。

  • echo 'c.ContentsManager.default_jupytext_formats = "ipynb,py"' >> ~/.jupyter/jupyter_notebook_config.pyコマンドを実行し、Jupyter NotebookとPythonスクリプトが連動するように設定します。

起動

pipenv run jupyter notebook

ブラウザ上でJupyter Notebookが開く

終了

Jupyter Notebookを起動しているターミナル上でCtrl+Cを押す

nbextensionsを導入

nbextesionsはjupyter notebookをカスタマイズするためのもの

pipenv install jupyter-contrib-nbextensions
pipenv install jupyter-nbextensions-configurator

nbextensionsを有効化

pipenv run jupyter contrib nbextension install --user
pipenv jupyter nbextensions_configurator enable --user

nbextensionsのオススメカスタマイズについてはこちら
http://pynote.hatenablog.com/entry/jupyter-notebook-nbextensions

syntax highlightの有効化

pipenv run jupyter nbextension enable highlight_selected_word/main

numpy, pandasのinstall

ここからは使いたいpackageを以下のようにインストールしていただけば大丈夫です。

pipenv install numpy pandas

まとめ

npmでの開発に慣れている方にはpipenvでpythonのプロジェクトを作るのは非常にオススメです。
pipenvでのプロジェクトを始めたいときは

pipenv install

でPipfile内にあるpackageがインストールされます。(npm installと同じですね)

以下に実際にやってみたものがあるので、すぐにjupyter notebookを使い始めたい方にどうぞ
https://github.com/YuanzhongLi/python_environment

8
5
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
8
5