vs code环境配置注意点

  • "cwd": "${fileDirname}":若有多个子目录,若想执行该子目录的py文件,需要在configurations下配置该选项,表明当前工作目录为工作文件所在的文件夹;
  • 如何实现jupyter环境配置,使用如下配置

可以安装anaconda2和anaconda3,然后再vscode中的settings.json中设置需要的python目录,就可以实现不同的python切换。例如:settings.json中写入如下代码

{
    "python.pythonPath": "D:\Program Files\anaconda2\python.exe",
}

可以实现python2的需求以及numpy、matplotlib等anaconda中涉及到的所有库

  • 创建空白的Jupyter文件:使用Ctrl+Shift+P, 选中Python:Create New Blank Jupyter  Notebook
  • 修改vscode中python的全局配置,使用Ctrl+Shift+P,选中:Preferences:Open Settings(Json),将"python"中的内容修改为黑色Bold部分
{

    "code-runner.executorMap" : {
        // "python": "set PYTHONIOENCODING=utf8 && python"
        // 改成  $pythonPath $fullFileName"
        "python": {
            "python":"$pythonPath $fullFileName",
        }
    }


}
  •  修改工作目录下的settings.json,若是没有的话,可以手动创建,添加"cwd":表示当前文件为当前工作目录
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: 当前文件",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "cwd": "${fileDirname}", // 添加该条目
            // "env": {
            //     "PATH": "C:\Users\wucj\Anaconda3\Lib\site-packages\numpy"
            //   },
        }
    ]
}
  •  Anaconda环境配置:

conda info --env # 查看环境

conda --version # 查看版本

conda create -n py36 python=3.6 # 创建python3.6的环境,该环境的名字为py36

conda remove -n py36 --all # 删除名字为py36的环境

source activate py36(conda4是:conda activiate py36)# 激活环境

source deactivate(conda4是:conda deactivate py36) # 退出环境

  • vscode无法引入自定包的解决方案

找到..Anaconda3Libsite-packages的路径,并在该路径下面添加一个文件pythonwork.pth,并在该文件中添加自定义包所在的路径,即可。

原文地址:https://www.cnblogs.com/gwzz/p/12981154.html