简体   繁体   English

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

[英]Jupyter not working after downgrading Python (Non Conda)

There is a thread on addressing how to get Jupyter to link correctly after downgrading Python, but that is referring to a Conda install. 有一个线程致力于解决如何在降级Python之后使Jupyter正确链接,但这是指Conda安装。 My motivation for downgrading Python is the fact that TensorFlow is broken on Python 3.7 . 我降级Python的动机是, TensorFlow在Python 3.7上已被破坏

After uninstalling Jupyter and downgrading Python, I receive this error. 卸载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

How do I link Jupyter and Python correctly to work properly? 如何正确链接Jupyter和Python才能正常工作?

Thanks, Nakul 谢谢Nakul

First try to uninstall jupyter notebook: 首先尝试卸载Jupyter Notebook:

brew uninstall jupyter (if you are on mac) brew uninstall jupyter (如果您使用的是Mac)

or python3 -m pip uninstall jupyter python3 -m pip uninstall jupyter

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

python3 -m pip install jupyter --force

First, go the cd /usr/local/bin/ where jupyter is stored. 首先,转到cd /usr/local/bin/ ,其中存储了jupyter。

This you do by typing nano jupyter notebook 您可以通过键入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())

Then you need to change from #!/usr/local/opt/python/bin/python3.7 to #!/usr/local/opt/python/bin/python3.6 然后您需要从#!/usr/local/opt/python/bin/python3.7#!/usr/local/opt/python/bin/python3.6

This is how I fixed it. 这就是我解决的方法。

macOS: 苹果系统:

If you got Jupyter from brew, you can do: 如果您从Brew获得Jupyter,则可以执行以下操作:

brew link --overwrite jupyter

This will overwrite your /usr/local/bin/jupyter with a symlink to ../Cellar/jupyter/1.0.0_5/bin/jupyter 这将使用指向../Cellar/jupyter/1.0.0_5/bin/jupyter的符号链接覆盖/usr/local/bin/jupyter ../Cellar/jupyter/1.0.0_5/bin/jupyter

On my installation that file now looks like 在我的安装中,该文件现在看起来像

#!/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" "$@"

rather than the earlier 而不是较早的

#!/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())

This fixed your exact problem for me. 这为我解决了您的确切问题。

It risks collisions with the conda environment I am sure and so I am not hopeful it won't break something else. 我敢肯定它有可能与conda环境发生碰撞,因此我不希望它不会破坏其他功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM