无法在终端上运行 Jupyter Notebook

问题描述 投票:0回答:3

对于我的作业,我们需要使用 jupyter 笔记本来运行 .ipynb 文件。我用的是Mac,使用终端使用

pip install jupyter
安装,成功了。但是,当我尝试使用命令
jupter notebook
打开它时,我收到此错误。有什么想法吗?谢谢。 error

回溯(最近一次调用最后一次): 文件“/Library/Frameworks/Python.framework/Versions/3.6/bin/jupyter-notebook”,第 5 行,位于 从notebook.notebookapp导入main 文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/notebook/notebookapp.py”,第 76 行,位于 从 .base.handlers 导入 Template404、RedirectWithParams 文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/notebook/base/handlers.py”,第 24 行,位于 导入普罗米修斯客户端 文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/prometheus_client/init.py”,第 3 行,位于 从 。进口 ( 文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/prometheus_client/gc_collector.py”,第 43 行,位于 GC_COLLECTOR = GCCollector() 文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/prometheus_client/gc_collector.py”,第 14 行,位于 init 注册表.注册(自我) 文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/prometheus_client/registry.py”,第 26 行,在寄存器中 名称 = self._get_names(收集器) 文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/prometheus_client/registry.py”,第 66 行,在 _get_names 中 对于 desc_func() 中的度量: 文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/prometheus_client/gc_collector.py”,第 36 行,在收集中 collected.add_metric([生成], value=stat['collected']) 文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/prometheus_client/metrics_core.py”,第 126 行,在 add_metric self.samples.append(样本(self.name + '_total', dict(zip(self._labelnames, labels)), 值, 时间戳)) 类型错误:new() 缺少 1 个必需的位置参数:'exemplar'

python jupyter-notebook jupyter
3个回答
4
投票

从你的终端屏幕截图中,我可以看到你不在虚拟环境中,这意味着你正在使用全局Python。

需要检查和或考虑的三件事:

1. Python版本(管理和检查)。

为了避免您所看到的错误类型 - 创建 Python 版本的依赖性问题,可能需要使用像 conda 这样的包管理器或使用虚拟环境并在其中安装。

2.正确使用pip install:

如果您不想使用 vnev 或像 conda 这样的包管理器,请仔细检查您是否安装了正确的 python 版本,并在您想要使用的 python 版本上安装 jupyter。

python3.6 -m pip install jupyter

3.环境管理:

有许多不同的选项用于管理 python 版本,有些人喜欢在当前工作目录中创建虚拟环境并使用以下方式激活它们:

python3.6 -m pip install virtualenv
python3.6 -m venv env_name 
source env_name/bin/activate

激活后,您的终端将显示:

(env_name) jeffmpro.... 

然后您可以在此环境中 pip install jupyter,然后将使用以下命令运行:

jupyter notebook

如果您想使用 shims 全局管理 python 版本和虚拟环境,您可以使用名为 pyenv 的包来实现:

https://github.com/pyenv/pyenv

https://github.com/pyenv/pyenv-virtualenv

我还会在 mac 上使用 homebrew 在命令行中管理安装。

https://brew.sh/

希望这有帮助:-)


1
投票

正确答案其实是评论里的,我会在这里报告给未来的观众:

pip install jupyter
pip install notebook
jupyter-notebook your-file.ipynb

再见!


0
投票

就我而言,我只使用:

jupyter-notebook /path/to/note_book.ipynb

这对我有用。

© www.soinside.com 2019 - 2024. All rights reserved.