降级Python后,Jupyter无法正常工作(Non Conda)

时间:2018-10-26 01:52:11

标签: python jupyter

There is a thread解决了降级Python后如何使Jupyter正确链接的问题,但这是指Conda安装。我降级Python的动机是因为TensorFlow is broken on Python 3.7

在卸载Jupyter并降级Python之后,我收到此错误。

/usr/local/bin/jupyter: /usr/local/Cellar/jupyter/1.0.0_5/libexec/bin/jupyter: /usr/local/opt/python/bin/python3.7: bad interpreter: No such file or directory
/usr/local/bin/jupyter: line 2: /usr/local/Cellar/jupyter/1.0.0_5/libexec/bin/jupyter: Undefined error: 0

如何正确链接Jupyter和Python才能正常工作?

谢谢, 那库尔

3 个答案:

答案 0 :(得分:2)

首先尝试卸载jupyter笔记本:

brew uninstall jupyter(如果在Mac上)

python3 -m pip uninstall jupyter

然后通过以下方式强制重新安装jupyter:

python3 -m pip install jupyter --force

答案 1 :(得分:0)

首先,转到存储jupyter的cd /usr/local/bin/

您可以通过输入nano jupyter notebook

#!/usr/local/opt/python/bin/python3.7
# -*- 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())

然后,您需要从#!/usr/local/opt/python/bin/python3.7更改为#!/usr/local/opt/python/bin/python3.6

这就是我修复它的方式。

答案 2 :(得分:0)

macOS:

如果您从酿造中获得Jupyter,则可以:

brew link --overwrite jupyter

这将使用指向/usr/local/bin/jupyter的符号链接覆盖您的../Cellar/jupyter/1.0.0_5/bin/jupyter

在我的安装中,该文件现在看起来像

#!/bin/bash
JUPYTER_PATH="/usr/local/etc/jupyter" PYTHONPATH="/usr/local/Cellar/jupyter/1.0.0_5/libexec/lib/python3.7/site-packages:/usr/local/Cellar/jupyter/1.0.0_5/libexec/vendor/lib/python3.7/site-packages" exec "/usr/local/Cellar/jupyter/1.0.0_5/libexec/bin/jupyter" "$@"

而不是早期的

#!/usr/local/Cellar/python/3.6.4_2/bin/python3.6

# -*- 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())

这为您解决了确切的问题。

我敢肯定它可能会与conda环境发生冲突,因此我不希望它不会破坏其他内容。