Tricks in maintenance of coding environments
Category:
Coding
Tags:
cheat sheet
Various toolchains have been set up to facilitate daily chores. However, setting up and maintaining the environment becomes troublesome. Here, some common commands and methods are summarized.
Ubuntu
- Change the apt-get environment to aliyun. First back up the original list.
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
Then, edit /etc/apt/sources.list
. The content of the file can be found in the aliyun homepage. Finally, run
sudo apt-get update
- Grant user permission with
sudo chown
It is used to temporarily grant a super user permission.
sudo chrown -R $USER [FOLDER]
-
Monitoring system resources, a better way: bashtop
-
GPU monitoring:
nvidia-smi
WSL
Always use WSL2
- Check current version
wsl.exe -l -v
lsb_release -a
- Show remote (WSL) directory in windows explorer
explorer.exe .
Recommended docker image
Thanks to Hongjia Liu from the Department of Radiotherapy.
- Basic data science environment
sudo docker run --name [DOCKER_NAME] -p 10000:8888 -e JUPYTER_ENABLE_LAB=yes -v [LOCAL_DIR:~/docker]:/home/jovyan/work jupyter/datascience-notebook:latest
- GPU-enabled, advanced data science environment
An environment integratingzsh
,tensor-flow
,pytorch
, and etc.
sudo docker run -d --name <CONTAINER_NAME> -p <LOCAL_PORT>:8080 --gpus all -v "<LOCAL_DIR>:/workspace" --shm-size 10240m --env AUTHENTICATE_VIA_JUPYTER="<TOKEN>" mltooling/ml-workspace-gpu:0.13.2
<TOKEN>
is a paraphrase to assess the container. The CUDA version of the host server must be CUDA-11.2. The host server shall not be an LXC virtual machine.
Jupyter Notebook
- To set breakpoint
from IPython.core.debugger import set_trace
set_trace()
- A workaround to skip a certain cell when running the notebook
%%script skip-cell
- To use a conda environment as a kernel
conda info --envs
conda activate myenv
python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
# To uninstall
jupyter kernelspec list
jupyter kernelspec uninstall myenv
Python
- Useful pip mirrors
# 清华源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# 阿里源
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
# 腾讯源
pip config set global.index-url http://mirrors.cloud.tencent.com/pypi/simple
# 豆瓣源
pip config set global.index-url http://pypi.douban.com/simple/
Git
- Proxy
git config --global https.proxy http://127.0.0.1:1080
git config --global https.proxy https://127.0.0.1:1080
git config --global --unset http.proxy
git config --global --unset https.proxy
- SSH key
In git bash
ls -al ~/.ssh
ssh-keygen -t ed25519 -C "[email protected]"
ssh-agent
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
ssh -T [email protected]
- Change remote URI
Github recently ask clients to use ssh everywhere. It is worthwhile to switch from HTTPS to SSH.
git remote -v
# View existing remote
git remote set-url origin git://new_uri.git
# Change
git remote -v
# Validate
R
- To update R on Windows
install.packages("installr") # if not previously installed
library(installr)
updateR()