2

There is a thread on addressing how to get Jupyter to link correctly after downgrading Python, but that is referring to a Conda install. My motivation for downgrading Python is the fact that TensorFlow is broken on Python 3.7.

After uninstalling Jupyter and downgrading Python, I receive this error.

/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?

Thanks, Nakul

3 Answers3

3

First try to uninstall jupyter notebook:

brew uninstall jupyter (if you are on mac)

or python3 -m pip uninstall jupyter

then force reinstall jupyter by:

python3 -m pip install jupyter --force

Yushen Ye
  • 31
  • 1
3

First, go the cd /usr/local/bin/ where jupyter is stored.

This you do by typing 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

This is how I fixed it.

Ahoren
  • 66
  • 4
1

macOS:

If you got Jupyter from brew, you can do:

brew link --overwrite jupyter

This will overwrite your /usr/local/bin/jupyter with a symlink to ../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.

jtlz2
  • 7,700
  • 9
  • 64
  • 114