VSCode中 Python3环境的设置

in ide with 0 comment

以下为:vscode 版本 1.31.1的关于python3运行环境的设置。

vscode下载及python虚拟环境的新建

  1. vscode下载地址
    https://code.visualstudio.com/Download,在这里我选择的是windows64位系统绿色版,下载完成后解压即可。
  2. python3虚拟环境的设置
    打开cmd,运行virtualenv D:developpythonvscodeenv,创建关于vscode虚拟环境。

设置vscode下python3环境

  1. 设置vscode语言为中文,设置步骤如下,最后点击下载,待完成后重启既可以。
    中文.PNG
  2. 安装python插件,和以上方法类似,搜索python,如下:
    下载python.PNG
  3. 添加调试设置:新建一个文件夹工作区,再点击菜单栏调试 —> 添加配置,在打开的launch.json文件中,进行以下的设置:

    {
    // 使用 IntelliSense 了解相关属性。
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [

       {
           "name": "Python3",
           "type": "python",
           "request": "launch",
           "stopOnEntry": false,
           "pythonPath": "D:\\develop\\python\\vscodeenv\\Scripts\\python", //python3的安装路径
           "program": "${file}",
           "cwd": "${workspaceFolder}",
           "env": {},
           "envFile": "${workspaceFolder}/.env",
           "debugOptions": [
               "RedirectOutput"
           ]
       }  
       {
           "name": "Python: Terminal (integrated)",
           "type": "python",
           "request": "launch",
           "stopOnEntry": false,
           "pythonPath": "D:\\develop\\python\\vscodeenv\\Scripts\\python",
           "program": "${file}",
           "cwd": "",
           "console": "integratedTerminal",
           "env": {},
           "envFile": "${workspaceFolder}/.env",
           "debugOptions": []
       },
       {
           "name": "Python: Terminal (external)",
           "type": "python",
           "request": "launch",
           "stopOnEntry": false,
           "pythonPath": "D:\\develop\\python\\vscodeenv\\Scripts\\python",
           "program": "${file}",
           "cwd": "",
           "console": "externalTerminal",
           "env": {},
           "envFile": "${workspaceFolder}/.env",
           "debugOptions": []
       },
       {
           "name": "Python: Django",
           "type": "python",
           "request": "launch",
           "stopOnEntry": true,
           "pythonPath": "D:\\develop\\python\\vscodeenv\\Scripts\\python",
           "program": "${workspaceFolder}/manage.py",
           "cwd": "${workspaceFolder}",
           "args": [
               "runserver",
               "--noreload",
               "--nothreading"
           ],
           "env": {},
           "envFile": "${workspaceFolder}/.env",
           "debugOptions": [
               "RedirectOutput",
               "Django"
           ]
       },      

    ]
    }

  4. 修改用户设置:经过以上步骤,还未选择到自己想要的python虚拟环境,需要修改用户设置。

1>.在vscode界面运行:Ctrl + Shift + P ; 输入Open Settings
2>.在弹出的界面中,搜索“pythonPath”,步骤如下:
修改用户设置.PNG
3>.在settings.json中,设置:"python.pythonPath": "D:\develop\python\vscodeenv\Scripts\python"
4>.此时运行新建的python,即使用了我们的虚拟环境vscodeenv运行。
成功.PNG

Responses