Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jupyter command not found in terminal MacOS

For some reason, when I pip3 everything, it goes all under this PATH /Users/XXX/Library/Python/3.8/bin same for my notebook.

So I opened my vscode and go to .zshrc and add export PATH=$PATH:/Users/XXX/Library/Python/3.8/bin to my path.

And I go to terminal jupyter notebook I got zsh: /Users/XXX/Library/Python/3.8/bin/jupyter: bad interpreter: /usr/local/bin/python3: no such file or directory

And then I go back to .zshrc and change the path to export PATH=$PATH:/Users/XXX/Library/Python/3.8/bin/jupyter-notebook and I add to the path, it got zsh: command not found: jupyter

I refuse to use conda.. no particular reason.

What should I do next?

UPDATE

The actual reason I want to solve above issue is because I have my jupyter kernel running fine in my VS code, but cannot convert to HTML. That's why I thought install web-based Jupyter Notebook can help me solve this issue. Apparently, it did not. when I try to convert to HTML in web-based notebook, it give me the 500 Internal Error.

I also tried something like this python3 -m jupyter nbconvert --to html notebook.ipynb And I got the following error:

Traceback (most recent call last):
  File "/Users/zhengyangzhang/Library/Python/3.8/lib/python/site-packages/traitlets/traitlets.py", line 528, in get
    value = obj._trait_values[self.name]
KeyError: 'template_paths'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/zhengyangzhang/Library/Python/3.8/bin/jupyter-nbconvert", line 8, in <module>
    sys.exit(main())
  File "/Users/zhengyangzhang/Library/Python/3.8/lib/python/site-packages/jupyter_core/application.py", line 270, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "/Users/zhengyangzhang/Library/Python/3.8/lib/python/site-packages/traitlets/config/application.py", line 664, in launch_instance
    app.start()
  File "/Users/zhengyangzhang/Library/Python/3.8/lib/python/site-packages/nbconvert/nbconvertapp.py", line 350, in start
    self.convert_notebooks()
  File "/Users/zhengyangzhang/Library/Python/3.8/lib/python/site-packages/nbconvert/nbconvertapp.py", line 518, in convert_notebooks
    cls = get_exporter(self.export_format)
  File "/Users/zhengyangzhang/Library/Python/3.8/lib/python/site-packages/nbconvert/exporters/base.py", line 102, in get_exporter
    if getattr(exporter(config=config), 'enabled', True):
  File "/Users/zhengyangzhang/Library/Python/3.8/lib/python/site-packages/nbconvert/exporters/templateexporter.py", line 325, in __init__
    super().__init__(config=config, **kw)
  File "/Users/zhengyangzhang/Library/Python/3.8/lib/python/site-packages/nbconvert/exporters/exporter.py", line 114, in __init__
    self._init_preprocessors()
  File "/Users/zhengyangzhang/Library/Python/3.8/lib/python/site-packages/nbconvert/exporters/templateexporter.py", line 491, in _init_preprocessors
    conf = self._get_conf()
  File "/Users/zhengyangzhang/Library/Python/3.8/lib/python/site-packages/nbconvert/exporters/templateexporter.py", line 507, in _get_conf
    for path in map(Path, self.template_paths):
  File "/Users/zhengyangzhang/Library/Python/3.8/lib/python/site-packages/traitlets/traitlets.py", line 556, in __get__
    return self.get(obj, cls)
  File "/Users/zhengyangzhang/Library/Python/3.8/lib/python/site-packages/traitlets/traitlets.py", line 535, in get
    value = self._validate(obj, dynamic_default())
  File "/Users/zhengyangzhang/Library/Python/3.8/lib/python/site-packages/nbconvert/exporters/templateexporter.py", line 518, in _template_paths
    template_names = self.get_template_names()
  File "/Users/zhengyangzhang/Library/Python/3.8/lib/python/site-packages/nbconvert/exporters/templateexporter.py", line 601, in get_template_names
    raise ValueError('No template sub-directory with name %r found in the following paths:\n\t%s' % (base_template, paths))
ValueError: No template sub-directory with name 'lab' found in the following paths:
    /Users/zhengyangzhang/Library/Jupyter
    /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/share/jupyter
    /usr/local/share/jupyter
    /usr/share/jupyter

Can someone take a look again and see what's the issue here?

like image 670
Sheldon Avatar asked Nov 14 '22 22:11

Sheldon


2 Answers

OK, some things to look at. First this is what my path on OSX looks like (bash but last time I checked zsh is highly compatible):

showpath ()
{
    IFS=':' read -a array <<< "$PATH";
    for index in "${!array[@]}";
    do
        echo "$index ${array[index]}";
    done
}
$ showpath 
(some stuff removed)
1 /opt/local/bin  šŸ‘ˆ I use macports, this is where MY Python is
2 /usr/local/bin  šŸ‘ˆ and also brew, probably where your Python is
3 /usr/bin
4 /bin
5 /usr/sbin
6 /sbin
8 /opt/local/sbin
10 /Users/xxx/bin
11 /Users/xxx/Library/Python/3.8/bin  šŸ‘ˆ this also needs to be on your path

OK, now, after deactivating my virtualenv, this is what I see:

$ which python3.8
/opt/local/bin/python3.8  # you'll be in /usr/local/bin if using brew
which pip3
/Users/xxx/Library/Python/3.8/bin/pip3

If I ls | egrep 'jupyter|pip3' in /Users/xxx/Library/Python/3.8/bin I get:

jupyter
jupyter-bundlerextension
jupyter-console
jupyter-kernel
jupyter-kernelspec
jupyter-migrate
jupyter-nbconvert
jupyter-nbextension
jupyter-notebook
jupyter-qtconsole
jupyter-run
jupyter-serverextension
jupyter-troubleshoot
jupyter-trust
pip3
pip3.8

So, basically, if you can see pip3 from the shell, your path should work for jupyter as well.

Now, if you are using brew, that's where /usr/local/bin/python3 comes in. And that should already be on your path, courtesy of brew. I am guessing you have a python3.8 entry there, but no python3.

Suggestion:

Maybe you should try to symlink via ln -s python3.8 python3 in that directory and that will make jupyter see that plain old python3 it wants. You may have to sudo to get that link working (if so make sure your user has appropriate permissions on the link).

Also, to see things from plain old Python point of view:

>>> import sys
>>> for v in sys.path: print(v)
/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python38.zip
/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8
/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/lib-dynload

šŸ‘‡ this is a deeper-level sibling of where the `bin` for Python keeps the 
executables like pip3 and jupyter
/Users/xxx/Library/Python/3.8/lib/python/site-packages  


/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-package

Also, something else to look at. Remember that which jupyter?

Let's look at what it says, and mostly at its shebang.

$ pwd
/Users/xxx/Library/Python/3.8/bin
$ cat jupyter
#!/opt/local/bin/python3.8  šŸ‘ˆ that's mine, but guessing 
                            #yours says `/usr/local/bin/python3`


# -*- coding: utf-8 -*-
import re
import sys
from jupyter_core.command import main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

like image 190
JL Peyret Avatar answered Dec 22 '22 11:12

JL Peyret


Answer for Notebook Unable to start from Terminal:

After export PATH=$PATH:/Users/XXX/Library/Python/3.8/bin is in your .zshrc or .bashrc (if you're using bash), you go back to your terminal and run python3 -m jupyter notebook

And then the notebook will start.

like image 43
Sheldon Avatar answered Dec 22 '22 09:12

Sheldon