简体   繁体   中英

jupyter notebook/lab terminal python version

How do I change the python version of jupyter lab's terminal?

For instance, in the terminal of jupyter lab, which python would return /usr/bin/python , and python -V --> Python 2.7.10 ;
But in my laptop's terminal, which python --> /Users/name/anaconda3/bin/python , python -V --> Python 3.7.5 .

Thanks!

Install Jupyter using that Python and uninstall from Python 2 (because Python 2 is end of life and you shouldn't be installing things into the System python anyway)

/Users/name/anaconda3/bin/python -m pip install jupyter

Or define a new kernel for Jupyter that uses that Python path (after installing ipython into it)

{
  "argv": [
    "/Users/name/anaconda3/bin/python",
    "-m",
    "ipykernel",
    "-f",
    "{connection_file}"
  ],
  "display_name": "Anaconda 3",
  "language": "python"
}

Bonus : Learn pyenv

Here's what I did to resolve this. I reset the PATH variable to be the default at the top of my .zshrc file (on a Mac) before anything else touches PATH. That is, I have included these two lines at the top:

PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
export PATH

After restarting Jupyter Lab, doing which python now gives me the correct python version instead of 2.7 like it was before. According to a comment here , the PATH variable is flipped so it causes issues about which Python to source first. By enforcing the default PATH before Anaconda gets to it, it will ensure that Anaconda's Python gets sourced first in the Jupyter Lab terminal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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