vs code搭建python和tensorflow环境

anaconda 安装tensorflow-gpu环境见https://www.cnblogs.com/wintersoft/p/11620267.html

 

vscode中设置python虚拟环境
Ctrl+Shift+P,选择Python:Select Interpreter,选中tensorflow-gpu虚拟环境
会自动在settings.json文件中生成,如:

{
  "python.pythonPath": "C:\\ProgramData\\Anaconda3\\envs\\tensorflow-gpu\\python.exe"
}

 

或手动配置,自己在.vscode文件夹里新建settings.json

{
  "python.pythonPath": "C:\\ProgramData\\Anaconda3\\envs\\tensorflow-gpu\\python.exe",
  "python.autoComplete.extraPaths": [
    "C:\\ProgramData\\Anaconda3\\envs\\tensorflow-gpu",
    "C:\\ProgramData\\Anaconda3\\envs\\tensorflow-gpu\\Lib\\site-packages"
  ],
  "python.autoComplete.addBrackets": true
}

 

F5调式特定启动文件,可修改为:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python: 当前文件",
      "type": "python",
      "request": "launch",
      // "program": "${file}",
      "pythonPath": "C:\\ProgramData\\Anaconda3\\envs\\tensorflow-gpu\\python.exe",
      "program": "${workspaceRoot}\\hello.py",
      "console": "integratedTerminal",
      "env": {"PYTHONPATH":"${workspaceRoot}"},
      "envFile": "${workspaceRoot}/.env",
    }
  ]
}

 

VS code python 环境下提示找不到 module报unresolved import "xxx"
https://github.com/DonJayamanne/pythonVSCode 该插件的BUG造成的
进入launch.json文件,configurations节点下加入:
"env": {"PYTHONPATH":"${workspaceRoot}"},
"envFile": "${workspaceRoot}/.env",

进入settings.json文件,加入:
"python.jediEnabled": false,

然后重启vs code

 

上一篇:PAT甲级 1003 Emergency (25分)题目理解以及测试点的易错点


下一篇:python爬虫和数据可视化学习(2) 第一个python程序