GCP with GUI Desktop and VNC

by allenlu2007

Reference:  https://medium.com/google-cloud/graphical-user-interface-gui-for-google-compute-engine-instance-78fccda09e5c

需要 100% follow the above article (including the OS: Ubuntu TLS 14.04). 


Step1: Create a VM instance running Ubuntu 14.04 TLS OS

本文用 project: compute-engine and VM instance: tf 為例。External IP is




Step 2: Installing a VNC server and Gnome desktop

(a) install VNC server
$ sudo apt-get update

 此時尚未有 (GUI) desktop, 所以還需要 install desktop for local operation or VNC.

 可以選用自己喜歡的 desktop.  

 (b) 或是用 Gnome desktop

$ sudo apt-get install gnome-core

$ sudo apt-get install vnc4server

Install 完成後仍然回到 command line prompt.

(c) run vncserver and set password.

$ vncserver

Setpassword: axxxxxx

$ nc localhost 5901
RFB 003.008
=> 確認 vncserver is listening

$ vncserver -kill :1
$ vim .vnc/xstartup

Run again:
$ vncserver

再來要開放 firewall, 主要是 tcp:5901.  細節可以參考 reference.


View story at Medium.com





VNC Remote Desktop 的優點:

vnc client 比起 command line shell 好多了。

1. Vnc 穩定性比 command line shell 好。Notebook 開關 vnc reconnect 非常容易恢復。

2. 可以使用 multiple terminals.  同時處理 multiple tasks.

3. 可以 install gui 版的 tools. 例如 emacs, tensorboard, etc.



Step 3: Installing 必須的 tools: emacs, python, tensorflow

(Next time to run tensor flow:  $ source activate tensorflow)


1. Install emacs.  $ sudo apt-get install emacs

自動 install emacs 24.3.1.

2. Install python 以及相關的 packages (numpy, scipy, etc.) and tensorflow.


我們先從 Google tensorflow installation 反推:


We support different ways to install TensorFlow:

  • Pip install: Install TensorFlow on your machine, possibly upgrading previously installed Python packages. May impact existing Python programs on your machine.
  • Virtualenv install: Install TensorFlow in its own directory, not impacting any existing Python programs on your machine.
  • Anaconda install: Install TensorFlow in its own environment for those running the Anaconda Python distribution. Does not impact existing Python programs on your machine.
  • Docker install: Run TensorFlow in a Docker container isolated from all other programs on your machine.
  • Installing from sources: Install TensorFlow by building a pip wheel that you then install using pip.

 根據我的經驗,使用 Anaconda install 大概是問題最小的方式。同時一次解決 python and tensorflow installations.

Install Anaconda: (建議先用 python 3.5)

Follow the instructions on the Anaconda download site.

Create a conda environment called tensorflow:

# Python 2.7
$ conda create
-n tensorflow python=2.7

# Python 3.4
$ conda create
-n tensorflow python=3.4

# Python 3.5
$ conda create
-n tensorflow python=3.5

 > mkdir downloads

> cd downloads

wget http://repo.continuum.io/archive/Anaconda3-4.4.0-Linux-x86_64.sh

bash Anaconda3-4.3.1-Linux-x86_64.sh


接下來是 create a conda environment and activate conda and install tensorflow.

source ~/.bashrc

Use $ which python to make sure it’s in anaconda3/bin/python

# Python 3.5
$ conda create
-n tensorflow python=3.5

$ source activate tensorflow 

此時 $ python —version => Python 3.5.3 :: Continuum Analytics, Inc.

# Linux/Mac OS X, Python 2.7/3.4/3.5, CPU only:
$ conda install -c conda-forge tensorflow

此時 (tensorflow) $  new prompt with (tensorflow) prefix.

下一步是確認 tensorflow 是否 ok.

Run python

>>>import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()













(a) pip use apt-get (Debian) or yum (centos or redhat)

   > sudo apt-get install python-pip

(b) install google cloud SDK 包含 gcloud, gsutil, bq, etc. command-line tools.  

How?   可以參考 https://cloud.google.com/sdk/downloads

Download sdk.

Run install.sh

Initialize SDK:  > sudo gcloud init

不過應該有更容易的方法 install Cloud SDK, to be checked.


(c) install App Engine Python SDK:  How : > sudo gcloud components install app-engine-python

(d) > sudo gcloud components install appenginepythonextras


接下來就是參考 git 的 tutorial


> sudo apt-get install git

> sudo  git clone https://github.com/GoogleCloudPlatform/appengine-flask-skeleton.git 

> cd appengine-flask-skeleton

> sudo pip install -r requirements.txt -t lib