当前位置: 首页 > 工具软件 > py2deb > 使用案例 >

WSL2+docker+go+py+vscode 开发环境搭建

岳硕
2023-12-01

linux

WSL2 安装

安装 windows terminal

  • 商店搜索安装
  • 推荐工具 MobaXterm

启用

  • 运行 ubuntu
  • powershell 执行 wsl

删除

wsl --unregister Ubuntu-20.04

备份与恢复

安装好的wsl可以通过备份恢复的方式实现“重装”

# 备份,系统名 备份文件名
wsl.exe --export Ubuntu-20.04 d:\u20.tar
# 恢复, 系统名 安装目录 备份的文件名
wsl.exe --import Ubuntu-20.04 c:\ubuntu20 d:\u20.tar 

root 默认登录

避免因权限问题导致的各类错误,尤其是 vscode 开发时对文件的访问权限。

ubuntu2004.exe config --default-user root

更新源

mv /etc/apt/sources.list /etc/apt/sources.list.bak
vi /etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
apt update
apt upgrade

安装go

wget -O go.tar.gz https://studygolang.com/dl/golang/go1.16.6.linux-amd64.tar.gz
tar -C /usr/local -xzf go.tar.gz
ln -s /usr/local/go/bin/go /usr/bin/go
apt install -y unzip make gcc build-essential
echo "export GOPROXY=https://goproxy.io" >> ~/.bashrc

安装 py

# 自带 py3.8
apt install -y python3-pip
ln -s /usr/bin/python3 /usr/bin/python
# python换源
mkdir -p ~/.pip/
echo '[global]
timeout = 6000
index-url = https://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host = mirrors.aliyun.com' > ~/.pip/pip.conf
# 常用组件
pip install --user --no-cache-dir pandas flask launchpadlib msgpack cx_Oracle SQLAlchemy paramiko redis psycopg2-binary xmltodict py_smtp color_log PyYAML pyecharts pipreqs twine openpyxl xlrd xlwt waitress pymysql py_ctp

安装 oracle

# 安装 oracle 19 client
wget https://download.oracle.com/otn_software/linux/instantclient/199000/oracle-instantclient19.9-basic-19.9.0.0.0-1.x86_64.rpm
wget https://download.oracle.com/otn_software/linux/instantclient/199000/oracle-instantclient19.9-devel-19.9.0.0.0-1.x86_64.rpm
## 工具
apt install alien -y
alien -i ./oracle-instantclient19.9-basic-19.9.0.0.0-1.x86_64.rpm
alien -i ./oracle-instantclient19.9-devel-19.9.0.0.0-1.x86_64.rpm
## 环境变量
echo 'export ORACLE_HOME="/usr/lib/oracle/19.9/client64"
export TNS_ADMIN="$ORACLE_HOME/network/admin"
export LD_LIBRARY_PATH="$ORACLE_HOME/lib"
export PATH="$ORACLE_HOME/bin:$PATH"' >> ~/.bashrc

安装 Docker

curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
usermod -aG docker $USER
service docker start
# docker-compose
curl -L https://get.daocloud.io/docker/compose/releases/download/1.3.1/docker-compose-`uname -s`-`uname -m` > /usr/bin/docker-compose
chmod a+x /usr/bin/docker-compose

加速&指定IP范围

# vi /etc/docker/daemon.json
{
    "bip": "192.167.1.1/24",
    "registry-mirrors": ["https://rztad8kb.mirror.aliyuncs.com"]
}

Win 开发环境搭建

oracle

官方链接 Oracle Software Downloads | Oracle

1. 下载解压
https://download.oracle.com/otn_software/nt/instantclient/1911000/instantclient-basic-windows.x64-19.11.0.0.0dbru.zip
2. 添加 instantclient 目录到path

mingw

mingw64 管理员运行 避免cgo错误
1. 在线安装工具:
https://nchc.dl.sourceforge.net/project/mingw-w64/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/installer/mingw-w64-install.exe
2. 安装选项:x86_64/ posix/ seh
3. 添加 bin 目录到 path
4. 测试:gcc -v

Go

连接 Go下载 - Go语言中文网 - Golang中文社区 (studygolang.com)

1. 下载安装
https://studygolang.com/dl/golang/go1.16.5.windows-amd64.msi
2. 添加 bin 目录到 path

Python

官方链接 Download Python | Python.org

1. 下载安装
https://www.python.org/ftp/python/3.8.10/python-3.8.10-amd64.exe
2. 添加 path
	2.1 python 例 D:\Python38\
	2.2 Scripts  例 D:\Python38\Scripts
3. 换源加速
	3.1 建 pip 目录
		mkdir ~\AppData\Roaming\pip
	3.2 cd ~
	3.3 notepad ~\AppData\Roaming\pip\pip.conf
[global]
timeout = 6000
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn
4. 升级 pip
python -m pip install --upgrade pip
5. 常用组件
pip install --user --no-cache-dir pandas flask launchpadlib msgpack cx_Oracle SQLAlchemy paramiko redis psycopg2-binary xmltodict py_smtp color_log PyYAML pyecharts pipreqs twine openpyxl xlrd xlwt waitress pymysql py_ctp

Git

官方链接 Git - Downloads (git-scm.com)

下载安装 https://github.com/git-for-windows/git/releases/download/v2.32.0.windows.2/Git-2.32.0.2-64-bit.exe

GitExtensions

官方链接 Releases · gitextensions/gitextensions · GitHub

安装 vscode

官方链接 Download Visual Studio Code - Mac, Linux, Windows

  • 提速方法
更新网站地址
https://az764295.vo.msecnd.net/stable/c3f126316369cd610563c75b1b1725e0679adfb3/VSCodeSetup-x64-1.58.2.exe
更新后的地址为:http://vscode.cdn.azure.cn/stable/...
这个就是国内的镜像了点开后你会发现速度直接起飞。

安装插件

  • Remote-WSL
  • One Dark Pro
  • VSCode Great Icons
  • Bracket Pair Colorizer 2
  • Go / Install tools
  • Py / Pylance
  • Markdown Preview Enhanced
  • YAML
  • Rainbow CSV
  • Docker

QA

powershell 管理员

# 无法加载 D:\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
> get-executionpolicy
> set-executionpolicy remotesigned
输入 y

安装oracle报权限错误

原因

所在路径不正确,在使用 windows terminal 时默认进入 ubuntu20 的 /mnt/c/$USER 导致的

解决

  • 使用 windows terminal 进入 ubuntu 后执行 cd ~ 在用户目录下进行操作
  • 使用 ubuntu 快捷方式
 类似资料: