简体   繁体   中英

AI Platform Notebook Always Python 2

I am trying to create a Python 3 Notebook in GCP AI Platform Notebooks but the kernel is always python 2.

After creating a new "Python 3" notebook, the kernel in the top right correctly shows python 3 but ! python --version ! python --version returns Python 2.7.13 and

x = 1
f"{x}"

throws a SyntaxError. Selecting Python 3 in the top right, restarting the kernel, and restarting the instance does not change the result.

I can see that python 3 is installed from terminal, $ python3 --version -> Python 3.5.3 so the launcher appears to be busted!

I then SSH'ed onto the instance, and ran jupyter notebook (which correctly points to python 3.5)

zre@intel-20200218:~$ jupyter notebook
[I 17:55:35.993 NotebookApp] JupyterLab extension loaded from /usr/local/lib/python3.5/dist-packages/jupyterlab
[I 17:55:35.993 NotebookApp] JupyterLab application directory is /usr/local/share/jupyter/lab
[I 17:55:36.453 NotebookApp] Serving notebooks from local directory: /home/zre

But still hit this behavior: enter image description here

This happens because of different python version present in system

ls /usr/bin/python*

when you do this you will be seeing a output like this /usr/bin/python /usr/bin/python2 /usr/bin/python2.7 /usr/bin/python3
/usr/bin/python3.5 /usr/bin/python3.5m /usr/bin/python3m

Open ~/.bashrc file and add new alias to change your default python executable

alias python='/usr/bin/python3.5'
. ~/.bashrc

Now check your python version

python --version

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