0%

WSL 信息记录

记录WSL的相关操作

安装与卸载

安装 :

下载好对应的程序,解压到目标目录中双击安装程序进行安装

卸载 :

1
2
3
4
5
#列出已安装的wsl
wsl -l

#卸载目标系统
wsl --unregister CentOS8

重启

1
2
3
//以管理员权限运行cmd
net stop LxssManager //停止
net start LxssManager //启动

Clash 设置

1
2
3
4
5
6
7
8
9
10
11
vi ~/.bashrc

#写入以下内容
export http_proxy=192.168.0.174:7890
export https_proxy=192.168.0.174:7890
export all_proxy=192.168.0.174:7890
export ALL_PROXY=192.168.0.174:7890
#ip和端口需要从clash客户端中获取

#然后执行
source ~/.bashrc

错误解决

yum装啥啥没有:

本条针对CentOS8-WSL

        配置yum源:CentOS8系统配置国内yum源 虽然CSDN越来越傻逼(仅指业务),但是解决问题还是有点用的。

RPM数据库损坏:

本条针对CentOS8-WSL

        配置完yum源之后 准备安装Python依赖,结果

1
2
3
4
5
6
7
8
9
10
11
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
RPM: error: db5 error(-30969) from dbenv->open: BDB0091 DB_VERSION_MISMATCH: Database environment version mismatch
RPM: error: cannot open Packages index using db5 - (-30969)
RPM: error: cannot open Packages database in /var/lib/rpm
The downloaded packages were saved in cache until the next successful transaction.
You can remove cached packages by executing 'yum clean packages'.
Error: Could not run transaction.

于是乎又开始寻找解决方案,解决 RPM 数据库损坏的问题 | 楠格

DNF更新报错

本条针对CentOS8-WSL

1
2
3
4
5
6
7
8
9
10
11
[root@DESKTOP-2AK3L94 python3.6]# dnf update -y

Invalid configuration value: failovermethod=priority in /etc/yum.repos.d/Centos-8.repo; Configuration: OptionBinding with id "failovermethod" does not exist
Invalid configuration value: failovermethod=priority in /etc/yum.repos.d/Centos-8.repo; Configuration: OptionBinding with id "failovermethod" does not exist
Invalid configuration value: failovermethod=priority in /etc/yum.repos.d/Centos-8.repo; Configuration: OptionBinding with id "failovermethod" does not exist
Invalid configuration value: failovermethod=priority in /etc/yum.repos.d/Centos-8.repo; Configuration: OptionBinding with id "failovermethod" does not exist
Invalid configuration value: failovermethod=priority in /etc/yum.repos.d/Centos-8.repo; Configuration: OptionBinding with id "failovermethod" does not exist
Last metadata expiration check: 1:50:47 ago on Fri 21 Jan 2022 09:09:39 PM CST.
Dependencies resolved.
Nothing to do.
Complete!

经过多方查找,发现是 dnf 不支持failovermethod 选项。很久以前,该选项已从存储库配置文件(包 fedora-repos)的分发版本中删除,所以解决方案就是删除/etc/yum.repos.d/CentOS-Base.repo里面的failovermethod=priority这个选项

参考:

1.报错 配置:ID 为 “failovermethod” 的 OptionBinding 不存在,解决办法 - 约德尔萌人的个人博客

2.Bug 1961083 - Invalid configuration value: failovermethod=priority in repo config files


安装Python3.6

本条针对CentOS8-WSL

        本来装CentOS8就是因为他能直接用Python3,但是当我输入Python、Python3、Python3.6都没用但是yum有用之后我就疑惑了:

1
2
3
4
5
[root@DESKTOP-2AK3L94 python3.6]# vi /usr/bin/yum

#!/usr/libexec/platform-python
...
...

因为通常yum的首行是会标注用的python版本的,但是看到这个版本我就沉默了,搜索之后,发现这是一个CentOS为了不限制用户Python版本所做出的决定

“这并不是说 Python 在 CentOS 上默认不再可用。 Yum 和新的 DNF 包管理器都特别依赖 Python。 他们现在依赖的 Python 版本被称为“Platform-Python”。 出于所有意图和目的,“Platform-Python”版本不应被用作使用 Python 的交互方式。”

来自: 如何在 CentOS 8 上安装 Python 2 和 3

1
2
3
dnf update -y
dnf install python3 -y
python3 -V

配置虚拟环境:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#安装虚拟环境包
pip3 install virtualenv

#在工作文件夹中创建相应的虚拟环境并指定Python版本
[root@DESKTOP-2AK3L94 WebLearn]$ virtualenv webenv --python=python3
#此命令会在当前目录下创建一个以虚拟环境名同名的文件夹

#激活虚拟环境
[root@DESKTOP-2AK3L94 WebLearn]$ source webenv/bin/activate

#关闭虚拟环境
deactivate

#删除虚拟环境,只需删除它的文件夹
rm -rf venv

连接VScode

  1. 安装Remote - WSL插件

  2. 选择远程资源管理器中的wsl系统