使用VScode进行Python开发

一、Microsoft Store中安装:terminal

二、PowerShell中执行:

[win10新版或者win11使用:
单个命令安装运行 WSL 所需的一切内容(需要重启计算机):wsl --install
检查发行版的 WSL 版本:wsl -l -v
]
win10旧版
1.dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
2.dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
3.下载并安装:wsl_update_x64.msi
4.wsl --set-default-version 2

三、Microsoft Store中安装:ubuntu

项目资源上传路径:\\wsl.localhost\Ubuntu\home\zhs(或者\\wsl$\Ubuntu\home\zhs)

使用管理员连接terminal,在项目路径中依次执行以下命令(requirements.txt文件中存放的是项目中要引用的包):

1.sudo apt-get install libmysqlclient-dev
2.sudo apt-get install python-dev-is-python3
3.sudo apt install libpython3.11-dev
4.sudo apt-get install python-pip
5.sudo apt install python3-apt --fix-missing
6.sudo apt remove --purge python3-apt
7.sudo apt install pip
8.pip install -r ./requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
9.vi ~/.bash_profile
export PATH=$PATH:/home/zhs/.local/bin
10.source ~/.bash_profile

四、VScode关联项目

左下角点击,Running in Ubuntu(WSL 2)

五、启动(在项目中的app路径执行):

uvicorn api:app --reload

六、说明

不用PyCharm,是因为社区版不能连接WSL,有些引用包不能安装在Windows系统,但是PyCharm在Python开发中可以进行代码引用查看,这点比VScode友好

历史执行命令查看:history |grep pip
查看pip路径:which pip

 

posted @ 2023-04-09 18:41  借你耳朵说爱你  阅读(125)  评论(0编辑  收藏  举报