She*_*don 5 python zshrc jupyter-notebook nbconvert
出于某种原因,当我 pip3 所有东西时,它都在这个 PATH 下/Users/XXX/Library/Python/3.8/bin
与我的笔记本相同。
所以我打开了我的 vscode 并转到.zshrc并添加export PATH=$PATH:/Users/XXX/Library/Python/3.8/bin到我的路径中。
我去 jupyter notebook我得到的终端zsh: /Users/XXX/Library/Python/3.8/bin/jupyter: bad interpreter: /usr/local/bin/python3: no such file or directory
然后我返回.zshrc并将路径更改为export PATH=$PATH:/Users/XXX/Library/Python/3.8/bin/jupyter-notebook并添加到路径中,它得到了zsh: command not found: jupyter
我拒绝使用 conda ......没有特别的原因。
我接下来该怎么做?
更新
我想解决上述问题的实际原因是我的 jupyter 内核在我的 VS 代码中运行良好,但无法转换为 HTML。这就是为什么我认为安装基于 Web 的 Jupyter Notebook 可以帮助我解决这个问题。显然,它没有。当我尝试在基于网络的笔记本中转换为 HTML 时,它给了我500 Internal Error.
我也尝试过这样的事情python3 -m jupyter nbconvert --to html notebook.ipynb
,但出现以下错误:
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
Run Code Online (Sandbox Code Playgroud)
有人可以再看一下,看看这里有什么问题吗?
好的,有些事情需要注意。首先,这是我在 OSX 上的路径(bash但上次我检查的zsh是高度兼容的):
showpath ()
{
IFS=':' read -a array <<< "$PATH";
for index in "${!array[@]}";
do
echo "$index ${array[index]}";
done
}
Run Code Online (Sandbox Code Playgroud)
$ 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
Run Code Online (Sandbox Code Playgroud)
好的,现在,停用我的 virtualenv 后,我看到的是:
$ 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
Run Code Online (Sandbox Code Playgroud)
如果我ls | egrep 'jupyter|pip3'进去/Users/xxx/Library/Python/3.8/bin我得到:
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
Run Code Online (Sandbox Code Playgroud)
因此,基本上,如果您可以从 shell 中看到,您的路径也pip3应该有效。jupyter
现在,如果您正在使用brew,那就/usr/local/bin/python3有用了。而且这应该已经在您的路径上了,由 提供brew。我猜你那里有一个python3.8条目,但没有python3。
也许你应该尝试ln -s python3.8 python3在该目录中通过符号链接,这将使 jupyter 看到python3它想要的普通旧内容。您可能必须sudo使该链接正常工作(如果是这样,请确保您的用户对该链接具有适当的权限)。
另外,从普通的旧 Python 角度来看事情:
>>> 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
Run Code Online (Sandbox Code Playgroud)
另外,还有其他东西要看。还记得吗which jupyter?
让我们看看它说什么,主要是看它的内容。
$ 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())
Run Code Online (Sandbox Code Playgroud)