In this article, we will create a Python environment on Ubuntu on GCE. (Please set vim by yourself.) The specific things to do are as follows.
In the initial state, the service account is used internally. It is a lot of trouble, so it is recommended to log in with your own user account.
gcloud init
You will be asked variously, so authenticate as you were told and paste the verification code.
First, install zsh.
sudo apt-get install zsh -y
After that, I want to set the default shell to zsh, but the chsh
command doesn't work because I don't know the password. (Please tell me if there is a way)
for that reason,
vim ~/.bashrc
Open bashrc with etc. and at the end
exec /usr/bin/zsh
Is inserted. The default shell is now zsh.
Next, insert oh-my-zsh. (I think that each person is particular about it, so if you are particular about it, skip to [Building a Python environment](## Building a Python environment).)
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
You will be asked if you want to change the default shell, but of course set it to no
.
Enter the following as an external plug-in.
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-history-substring-search ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-history-substring-search
git clone https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:=~/.oh-my-zsh/custom}/plugins/zsh-completions
Let's change zshrc here.
~/.zshrc
export ZSH="${HOME}/.oh-my-zsh"
ZSH_THEME="candy"
plugins=(
git pip pyenv virtualenv zsh-syntax-highlighting zsh-autosuggestions history-substring-search zsh-completions
)
source $ZSH/oh-my-zsh.sh
After editing, load it once.
source ~/.zshrc
We will build a common virtual environment using pyenv and virualenv. First, install pyenv and virtualenv.
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshenv
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshenv
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.zshenv
source ~/.zshenv
git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.zshenv
source ~/.zshenv
Install your favorite version of Python. For example, like this.
pyenv install 3.6.5
pyenv virtualenv 3.6.5 default_env
pyenv global default_env
If you are particular about this, please skip it. First, put powerline-shell in the current virtual environment.
pip install powerline-shell
After that, edit zshrc again as follows.
~/.zshrc
export ZSH="${HOME}/.oh-my-zsh"
ZSH_THEME="candy"
function powerline_precmd() {
PS1="$(powerline-shell --shell zsh $?)"
}
function install_powerline_precmd() {
for s in "${precmd_functions[@]}"; do
if [ "$s" = "powerline_precmd" ]; then
return
fi
done
precmd_functions+=(powerline_precmd)
}
if [ "$TERM" != "linux" ]; then
install_powerline_precmd
fi
plugins=(
git pip pyenv virtualenv zsh-syntax-highlighting zsh-autosuggestions history-substring-search zsh-completions
)
source $ZSH/oh-my-zsh.sh
export LC_ALL="en_US.UTF-8"
export LANG=ja_JP.UTF-8
#----------------------The following is a private setting, so please omit it.----------------------#
#history file specification
HISTFILE=$HOME/.zsh-history
HISTSIZE=1000
SAVEHIST=10000
#Cd if not a command
setopt auto_cd
#List completion candidates
setopt auto_list
#Switch completion candidates in order with TAB
setopt auto_menu
#Automatically complements parentheses
setopt auto_param_keys
#Directory name completion at the end/Is automatically added to prepare for the next completion
setopt auto_param_slash
#Correct when a command is missed
setopt correct
#Mark the file type in the completion candidate list
setopt list_types
#Without specifying a clear dot.Match files starting with
setopt globdots
#If the directory is matched by expanding the file name, at the end/Add
setopt mark_dirs
#Complement at the cursor position even in the middle of a word
setopt complete_in_word
#The file name list is displayed on the spot while keeping the cursor position.
setopt always_last_prompt
#Do not beep
setopt nobeep
#vcs enabled
setopt prompt_subst
# #Treat the following as comments
setopt interactive_comments
#History sharing
setopt share_history
#If the command added to the history is the same as the old one, delete the old one
setopt hist_ignore_all_dups
Further customize.
mkdir -p ~/.config/powerline-shell && powerline-shell --generate-config >
Create the following 2 files.
python:~/.config/powerline-shell/original_color.py
from powerline_shell.themes.default import DefaultColor
class Color(DefaultColor):
USERNAME_FG = 15
USERNAME_BG = 4
USERNAME_ROOT_BG = 1
HOSTNAME_FG = 15
HOSTNAME_BG = 10
HOME_SPECIAL_DISPLAY = False
PATH_FG = 15
PATH_BG = 70
CWD_FG = 231
SEPARATOR_FG = 0
READONLY_BG = 1
READONLY_FG = 7
REPO_CLEAN_FG = 14
REPO_CLEAN_BG = 0
REPO_DIRTY_FG = 3
REPO_DIRTY_BG = 0
JOBS_FG = 4
JOBS_BG = 8
CMD_PASSED_FG = 255
CMD_PASSED_BG = 136
CMD_FAILED_FG = 255
CMD_FAILED_BG = 1
SVN_CHANGES_FG = REPO_DIRTY_FG
SVN_CHANGES_BG = REPO_DIRTY_BG
VIRTUAL_ENV_BG = 31
VIRTUAL_ENV_FG = 231
AWS_PROFILE_FG = 7
AWS_PROFILE_BG = 2
TIME_FG = 255
TIME_BG = 246
python:~/.config/powerline-shell/config.json
{
"segments": [
"virtual_env",
"aws_profile",
"ssh",
"cwd",
"git",
"git_stash",
"jobs",
"read_only",
"newline",
"set_term_title",
"svn",
"time",
"exit_code"
],
"cwd": {
"max_depth": 4,
"max_dir_size": 10,
"full_cwd": 1
},
"mode": "patched",
"theme": "~/.config/powerline-shell/original_color.py"
}
** Caution **
pip install
every time.Roboto Mono for Powerline
)
If it is left as it is, Jupyter cannot be used, so set it. You can use Jupyter by following ** jupyter settings ** on the following site. Reference: https://rf00.hatenablog.com/entry/2018/01/01/160820
*** If ssh runs out, Jupyter will drop, so it is recommended to set up tmux and use Jupyter in it. ** **
We recommend Stack Driver Monitoring Agent for GCE resource monitoring. If you put it in, you will be able to check the detailed memory usage etc. from the Agent tab next to the HOST tab on the upper right of here. (However, please note that you will be charged separately)
Install according to Official. By default, data is sent every 1 minute, but since I am concerned about the amount of charges, I will change it to send data every 3 minutes.
sudo vim /etc/stackdriver/collectd.conf
/etc/stackdriver/collectd.conf
Interval 180 #Changed from Interval 60
#No change below
sudo service stackdriver-agent restart
Recommended Posts