in Python

Visual Studio Code的几个问题

小结

最近在使用Visual Studio Code的时候,碰到几个问题:安装linting,添加额外的环境路径PYTHONPATH,ANACONDA,以及调试等等,进行了解决。

问题和解决

Linting Python in Visual Studio Code

Linging可以对Python语言错误进行检查,参考Linting Python in Visual Studio Code 进行安装使用。

Visual Studio Code代码浏览

参考How can I navigate back to the last cursor position in Visual Studio Code?
Alt + ← … navigate back 也就是ALT + 左箭头后退

Alt + → … navigate forward也就是ALT + 右箭头前进

pyc进行反编译

下载Easy Python Decompiler 这个软件可以对pyc进行反编译。

添加额外的PYTHONPATH环境路径

参考Stackoverflow: Visual Studio Code – How to add multiple paths to python path?
Using Python environments in VS Code

CTRL + SHIFT + P进入命令行再进入Python: Select Interpreter可以选择运行环境

CTRL + SHIFT + D进入调试设置,创建launch.json和settings.json

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",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true,
            "env": { "PYTHONPATH": "C:\\ProgramData\\Anaconda2:C:\\ProgramData\\Anaconda2\\Lib:C:\\ProgramData\\Anaconda2\\DLLs:C:\\ProgramData\\Anaconda2\\Lib\\lib-tk" }
        }
    ]
}

settings.json内容如下:

{
    "python.testing.pytestArgs": [
        "."
    ],
    "python.testing.unittestEnabled": false,
    "python.testing.pytestEnabled": true,
    "python.analysis.extraPaths": [
        "C:\\Program Files (x86)\\LibSE\\Python27",
        "C:\\Program Files (x86)\\LibSE"
    ]
}

以上python.analysis.extraPaths是额外的环境路径。

安装ANACONDA

参考Fix: ‘conda’ is not recognized as an internal or external command, operable program or batch file
https://repo.anaconda.com/archive/
对ANACONDA进行安装

参考

Linting Python in Visual Studio Code
How can I navigate back to the last cursor position in Visual Studio Code?
Easy Python Decompiler
Stackoverflow: Visual Studio Code – How to add multiple paths to python path?
Using Python environments in VS Code
How to add to the PYTHONPATH in Windows, so it finds my modules/packages?
Fix: ‘conda’ is not recognized as an internal or external command, operable program or batch file
https://repo.anaconda.com/archive/
Python debugging in VS Code

Write a Comment

Comment