首页 > 技术文章 > 配置作为开发生产力的Windows环境

jiading 2020-04-20 23:52 原文

配置Windows用于开发

山水轮流转,之前从Windows跳到了Linux的坑,某次偶然切回了双系统的Windows中,突然感觉这个系统其实挺好的:功能完善、生态强大、GUI自不必说,Powershell也不必Linux下的终端差多少。实际使用起来就是环境变量的配置和注册表使用比较麻烦一点,当时就想能不能以后在生产环境用Windows。用在Java开发上肯定是没问题的,但是机器学习怎么办?研究了半天,这里算是做个总结吧

  • 我知道Windows有个WSL,据说现在连GUI都能安装了。但是查了一下它不支持CUDA,遂gg
  • 想过虚拟机,但是效率太差
  • 最后没有什么办法,机器学习模型基于Linux是主流,虽然Windows也有CUDA也有脚本也能开发,虽然自己写无所谓,但是从github上下载的模型都是基于Linux的(主要是脚本和makefile),将这些都改成Powershell的脚本工作量是完全不可接受的。当然也不是完全没有办法,cygwin就是干这个的。
  1. Powershell不方便的地方:

    1. 不能在命令行中提权,想要升级为管理员必须重新打开(不是完全不可以,但是很麻烦,远不如Linux里一个sudo)
    2. 一部分常用命令和Linux不一样:像cd\ls这些都是一样的,但是像touch创建文件的命令就没有,而是叫New-Item(但是这里有个很蛋疼的地方就是有些文件夹只能是管理员账号才有权限创建文件,这时候你只能重开一个)。这个问题挺麻烦的其实,因为要重新学习一套命令,所以最可能的结果是用GUI的比例高了
  2. Anaconda在Powershell中创建虚拟环境需要在Powershell中添加一个脚本并在启动时执行(需要设置Powershell可以执行脚本),但是它执行起来非常慢(约1s),但是并不是每次使用Powershell都是需要这个功能的。当然Anaconda提供了Anaconda Prompt(其实就是在运行cmd的时候执行一个脚本),但是还是不方便啊

  3. Windows Terminal很好用,有了它就可以避免上面的问题。我们可以将Anaconda Prompt以及cmd、cygwin等等都添加到Windows Terminal中:

// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
"defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
{
    "$schema": "https://aka.ms/terminal-profiles-schema",
"profiles":
{
    "defaults":
    {
        // Put settings here that you want to apply to all profiles
    },
    "list":
    [
        {
            // Make changes here to the powershell.exe profile
            "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
            "name": "Windows PowerShell",
            "commandline": "powershell.exe",
            "hidden": false,
            "colorScheme": "Solarized Darcula-JD",
            "fontSize": 13,
            "startingDirectory": "./"
        },
        {
            // Make changes here to the cmd.exe profile
            "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
            "name": "cmd",
            "commandline": "cmd.exe",
            "hidden": false,
            "colorScheme": "Solarized Darcula-JD",
            "fontSize": 13,
            "startingDirectory": "./"
        },
        {
          // Make changes here to the cmd.exe profile
          "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6102}",
          "name": "Anaconda Prompt",
          "commandline": "cmd.exe \"/K\" E:\\Anaconda\\Scripts\\activate.bat E:\\Anaconda",
          "icon": "E:\\Anaconda\\bitbug_favicon.ico",
          "hidden": false,
          "colorScheme": "Solarized Darcula-JD",
          "fontSize": 13,
          "startingDirectory": "./"
      },
      {
        // Make changes here to the cmd.exe profile
        "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6105}",
        "name": "Cygwin",
        "commandline": "E:\\cygwin\\bin\\mintty.exe -i /Cygwin-Terminal.ico -",
        "icon": "E:\\cygwin\\Cygwin-Terminal.ico",
        "hidden": false,
        "colorScheme": "Solarized Darcula-JD",
        "fontSize": 13,
        "startingDirectory": "./"
    },
      {
          "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
          "hidden": false,
          "name": "Azure Cloud Shell",
          "source": "Windows.Terminal.Azure"
      }
  ]
},

// Add any keybinding overrides to this array.
// To unbind a default keybinding, set the command to "unbound"
"keybindings": []
}

guid是我随便写的,好像没什么影响

icon是我自己做的,可以用这个网站

这样,需要使用anaconda的时候打开一个新的标签页就可以了

(但是Windows Terminal好像并不能实现按住Shift后在右键中显示,不过这个功能是可以实现的:https://blog.csdn.net/Jioho_chen/article/details/101159291,实际使用也很方便)

  1. 我非常喜欢我Linux中gnome terminal的配色方案,但是我网上没有找到,自己凑合配了个:

            {
                "name": "Solarized Darcula-JD",
                "black": "#ceee3f",
                "red": "#f24840",
                "green": "#629655",
                "yellow": "#b68800",
                "blue": "#2075c7",
                "purple": "#797fd4",
                "cyan": "#15968d",
                "white": "#d2d8d9",
                "brightBlack": "#ceee3f",
                "brightRed": "#f24840",
                "brightGreen": "#78db5f",
                "brightYellow": "#52bf36",
                "brightBlue": "#2075c7",
                "brightPurple": "#797fd4",
                "brightCyan": "#15968d",
                "brightWhite": "#d2d8d9",
                "background": "#272a2d",
                "foreground": "#ced0d1"
              }
    

    里面的值已经被我改过了,和前面的英文并不对应

最后的效果如下:

用起来还是很舒服的,特别是配合Xshell\Xftp系列软件,生产力简直拉满

推荐阅读