Skip to content

Instantly share code, notes, and snippets.

@txoof
Last active October 6, 2022 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save txoof/c523e50e5919b31ea4da9322cf022f3b to your computer and use it in GitHub Desktop.
Save txoof/c523e50e5919b31ea4da9322cf022f3b to your computer and use it in GitHub Desktop.
Setup Python pyenv for Jupyter with nbconvert on Mac OS

If nbconvert throws a similar error, it is likely because the jupyter installation is not setup properly within a pyenv

ValueError: No template sub-directory with name 'python' found in the following paths:
	/Users/aciuffo/Library/Jupyter
	/opt/homebrew/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/share/jupyter
	/usr/local/share/jupyter
	/usr/share/jupyter

Setup pyenv

  • brew uninstall python
  • brew install python
  • brew install pyenv
  • pyenv install X.Y.Z -- use the pyenv install --list to find the appropriate python version
  • pyenv global X.Y.Z -- set the global pyenv version

Set Pyenv to set appropriate pyenv at login

in .zshrc:

PATH=$HOME/.pyenv/bin:$HOME/.pyenv/shims:$PATH # see note below
if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init --path)"
  eval "$(pyenv init -)"
fi

Note I use a custom zsh script for adding paths oh-my-zsh_custom/add_paths.zsh instead of directly adding to the PATH statement

#!/usr/bin/zsh

# Add any paths that could be included in the $PATH variable
# only paths that exist will be added
myPaths=($HOME/bin/ $HOME/bin/develtools $HOME/.local/bin /usr/local/opt/tcl-tk/bin /usr/local/opt/openssl/bin /usr/local/bin $HOME/.pyenv/bin $HOME/.pyenv/shims )

for each in "${myPaths[@]}"; do
  if [ -d $each ]; then
    # $path is a special array tied to the $PATH env var
    # only unique entries are appended
    path+=($each)
  fi
done

Open a new shell and verify that the pyenv shell is active:

$ which python3
/Users/aciuffo/.pyenv/shims/python3

Then run:

pip3 install jupyter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment