基于Python在Win环境下总是出现各类问题,想着采用新的WSL环境来部署运行Python项目。
一、安装WSL系统,参考微软官方教程。
wsl --install
安装完成后即可等待重启,然后运行Unbutu,首次会提示初始化,并设置用户名和密码,之后可在计算机里看到Linux目录。
二、安装pip等工具
Unbutu系统自带了python3,但是发现无pip命令,执行安装(sudo apt install python3-pip)时报错,报错如下
Package python3-pip is not available but is referred to by another package.
This may mean that the package is missing, has been obsoleted, oris only available from another source
E: Package 'python3-pip' has no installation candidate
执行以下命令后,即可
sudo apt-get update
sudo apt-get upgrade #Optional
sudo apt install python3-pip
三、后续安装virtualenv时会提示警告,导致无法使用该命令
WARNING: The script virtualenv is installed in '/home/desk/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
解决方案如下:
echo 'export PATH=$PATH:$HOME/.local/bin' >>~/.bashrc
source ~/.bashrc