VScode for Python and Julia

VS Code

VS code is good, but there are some pitfalls for programming and for markdown.

VS Code for Python Programming

Python Environment and Conda Env Selection

結論:直接用 conda create virtual environment with different python version and other packages. VS code cmd (not PS!) support conda!

Catch 1: PowerShell 本身不支持 conda!!! 在 VS Code 要用 conda activate xxx 必須先改變 input terminal!!

vs code更改預設終端 conda activate激活 - 簡書 (jianshu.com)

解決辦法:

輸入:Ctrl+Shift+P

輸入:terminal:select default profile

將預設的 PS 改為 cmd

Catch 2: 如果要改變 conda virtual environment. 可以在 cmd: conda activate base (or other env!).

Command line parameter passing

結論:VS code 沒有 direct support for command line parameters!!!! 必須使用 launch.json file to pass the command line parameters! Unbelievable!!

allenlu2009.github.io > .vscode > {} launch.json > JSON Language Features > [] configurations

幾個重點

  • launch.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
    // 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: current file",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "args": ["--infile", "2022-01-05-Optical_Flow_NN.md"],
            "console": "integratedTerminal",
            "cwd": "${fileDirname}",  // current working directory
            //"cwd": "${workspaceFolder}"
        }
    ]
}

幾個重點

  • args: specify command line arguments
  • cwd: current working directory. 可以是目前 python file directory ${fileDirname} 或是 workspace directory ${workspaceFolder}

VS Code Python Environment 設定

參考 Using Python Environments in Visual Studio Code

VS code 在處理不同 directories 的 python code 需要特別處理。什麽時候會用到? 就是在 testing 時。

一般會把 python source code (src) 和 python test code (tests) 放在不同的 directories.

VS Code for Julia Programming

Command line parameter passing -> same as Python reference

PyPlot doesn’t work with the plot pane

PyPlot doesn’t work with the plot pane · Issue #325 · julia-vscode/julia-vscode (github.com)

VS Code for Markdown

結論:基本我已經放棄用 VS code for markdown, 雖然有 plug-in such as preview enhance, etc. 不過我還是用 typora for markdown editing and preview.