天天看點

windows環境下VS Code+Python3的開發環境配置

寫在最前面:

不得不說,windows下VS Code的黑比PyCharm下的黑要黑多了,預設字型也更棒,用來做些小的算法練習再合适不過了,大型項目還是上PyCharm吧。

首先下載下傳VS Code

然後搜尋python,點選install

windows環境下VS Code+Python3的開發環境配置

然後我們需要修改兩個檔案

windows環境下VS Code+Python3的開發環境配置

- 點選 VS Code 的 檔案 > 首選項 > 設定 ,可以打開設定面闆; 

- 在 VS Code 中使用 Ctrl+Shift+P打開指令面闆,輸入Preferences: Open User Settings或Preferences: Open Workspace Settings。

一般來說,我們首先在某個盤建個檔案夾,然後再VS Code中選擇打開open folder,打開這個檔案夾。此時該檔案下會生産兩個json檔案,launch.json和settings.json。

配置如下:

settings.json:

{
    "python.linting.pylintEnabled": true,
    "python.linting.enabled": true,
    "python.pythonPath":"C:\\python3\\python"
}
           

選擇你的python環境的路徑

launch.json

{
    // 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 (Integrated Terminal)",
            "type": "python",
            "request": "launch",
            "pythonPath": "${config:python.pythonPath}",
            "program": "${file}",
            "console": "integratedTerminal"
        },
        {
            "name": "Python: Remote Attach",
            "type": "python",
            "request": "attach",
            "port": 5678,
            "host": "localhost",
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "."
                }
            ]
        },
        {
            "name": "Python: Module",
            "type": "python",
            "request": "launch",
            "module": "enter-your-module-name-here",
            "console": "integratedTerminal"
        },
        {
            "name": "Python: Django",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/manage.py",
            "console": "integratedTerminal",
            "args": [
                "runserver",
                "--noreload",
                "--nothreading"
            ],
            "django": true
        },
        {
            "name": "Python: Flask",
            "type": "python",
            "request": "launch",
            "module": "flask",
            "env": {
                "FLASK_APP": "app.py"
            },
            "args": [
                "run",
                "--no-debugger",
                "--no-reload"
            ],
            "jinja": true
        },
        {
            "name": "Python: Current File (External Terminal)",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "externalTerminal"
        }
    ]
}
           

添加一行 "pythonPath": "${config:python.pythonPath}",

然後一般我們需要裝個pylint的插件,規範代碼風格,然鵝,由于是内網,無法pip安裝,那我們就手動安裝。

在https://pypi.org/下載下傳好wheel或者tar.gz的檔案後,通過pip install xxx.wheel或者python setup.py install安裝。

在settings.json中添加下面一行

"python.linting.pylintPath": "C:\\python3\\Scripts\\pylint.exe"
           
windows環境下VS Code+Python3的開發環境配置