Visual Studio Code的Python扩展是高度可配置的。此页面描述了可以使用的关键设置。
有关在VS Code中使用设置的一般信息,请参阅“ 用户和工作空间设置 ”以及“ 变量”参考,以获取有关预定义变量支持的信息。
设置 | 默认 | 描述 |
---|---|---|
python.condaPath | "conda" | conda 可执行文件的路径。 |
python.pythonPath | "python" | Python解释器的路径,或包含Python解释器的文件夹的路径。可以使用${workspaceFolder} 和这样的变量${workspaceFolder}/.venv 。使用文件夹路径可以使与项目一起工作的任何人都可以在文件夹中创建.venv 适合其操作系统的环境,而不必指定确切的平台相关路径。settings.json 然后可以将该文件包含在源代码存储库中。 |
python.pipenvPath | "pipenv" | 用于激活的pipenv可执行文件的路径。 |
python.disableInstallationCheck | false | 如果设置为true ,则在未安装Python解释器的情况下,禁止扩展名发出警告。在macOS上,如果您使用的是操作系统安装的Python解释器,也会禁用显示的警告。通常建议在macOS上安装一个单独的解释器。 |
python.venvPath | "" | 创建虚拟环境的文件夹的路径。根据使用的虚拟化工具,它可以是项目本身:,也可以是${workspaceFolder} 所有虚拟环境并排放置的单独文件夹:.\envs ,~/.virtualenvs 等等。 |
python.envFile | "${workspaceFolder}/.env" | 包含环境变量定义的文件的绝对路径。请参阅配置Python环境-环境变量定义文件。 |
python.globalModuleInstallation | false | Specifies whether to install packages for the current user only using the --user command-line argument (the default), or to install for all users in the global environment (when set to true ). Ignored when using a virtual environment. For more information on the --user argument, see pip - User Installs. |
python.poetryPath | "poetry" | Specifies the location of the Poetry dependency manager executable, if installed. The default value "poetry" assumes the executable is in the current path. The Python extension uses this setting to install packages when Poetry is available and there's a poetry.lock file in the workspace folder. |
python.terminal.launchArgs | [] | Launch arguments that are given to the Python interpreter when you run a file using commands such as Python: Run Python File in Terminal. In the launchArgs list, each item is a top-level command-line element that's separated by a space (quoted values that contain spaces are a single top-level element and are thus one item in the list). For example, for the arguments --a --b --c {"value1" : 1, "value2" : 2} , the list items should be ["--a", "--b", "--c", "{\"value1\" : 1, \"value2\" : 2}\""] . Note that Visual Studio code ignores this setting when debugging because it instead uses arguments from your selected debugging configuration in launch.json . |
python.terminal.executeInFileDir | false | Indicates whether to run a file in the file's directory instead of the current folder. |
python.terminal.activateEnvironment | true | Indicates whether to automatically activate the environment you select using the Python: Select Interpreter command when a new terminal is created. For example, when this setting is true and you select a virtual environment, the extension automatically runs the environment's activate command when creating a new terminal (source env/bin/activate on macOS/Linux; env\scripts\activate on Windows). |
python.terminal.activateEnvInCurrentTerminal | false | Specifies whether to activate the currently open terminal when the Python extension is activated, using the virtual environment selected. |
python.logging.level | error | Specifies the level of logging to be performed by the extension. The possible levels of logging, in increasing level of information provided, are off , error , warn , info , and debug . When set to off , which is not recommended, basic information will still be shown such as startup information and commands run by the Python extension. At the error level, basic information and errors will be shown. At the warn level, basic, error, and warning information will be shown. At the info level, basic, error, warning, and additional information like method execution times and return values will be shown. At this time, the debug level doesn't display additional information. |
python.insidersChannel | off | Specifies whether to participate in the Insiders program and the channel to use. Set to weekly or daily to automatically download and install the latest Insiders builds of the Python extension, which include upcoming features and bug fixes. |
Workspace symbols are symbols in C source code generated by the ctags tool (described on Wikipedia and on ctags.sourceforge.net). To quote Wikipedia, ctags "generates an index (or tag) file of names found in source and header files of various programming languages." Where Python is concerned, ctags makes it easier to jump to defined functions and other symbols in C/C++ extension modules.
Setting (python.workspaceSymbols.) | Default | Description |
---|---|---|
tagFilePath | "${workspaceFolder}/.vscode/tags" | Fully qualified path to tag file (an exuberant ctag file), used to provide workspace symbols. |
enabled | true | Specifies whether to enable the Workspace Symbol provider. |
rebuildOnStart | true | Specifies whether to rebuild the tags file on start. |
rebuildOnFileSave | true | Specifies whether to rebuild the tags file on when saving a Python file. |
ctagsPath | "ctags" | Fully qualified path to the ctags executable; default value assumes it's in the current environment. |
exclusionPatterns | ["**/site-packages/**"] | Pattern used to exclude files and folders from ctags. |
Setting | Default | Description |
---|---|---|
python.jediPath | "" | Path to folder containing the Jedi library (folder should contain a jedi subfolder). |
python.jediMemoryLimit | 0 | Memory limit for the Jedi completion engine in megabytes. Zero (the default) means 1024 MB. -1 disables the memory limit check. |
python.languageServer | Jedi | Defines type of the language server (Microsoft, Jedi, None). Note that the language server requires a platform that supports .NET Core 2.1 or newer. |
The language server settings apply when python.jediEnabled
is false
. If you have any difficulties with the language server, see Troubleshooting in the language server repository.
Setting (python.analysis.) | Default | Description |
---|---|---|
diagnosticPublishDelay | 1000 | The number of milliseconds to wait before transferring diagnostic messages to the problems list. |
disabled errors warnings information | [] | List of diagnostics messages to suppress or show as errors, warnings, or information. See below for applicable values. The classification of messages affects both what's shown in the Problems window and in the editor (such as the color of the underlining). |
logLevel | "Error" | Defines the types of log messages that language server writes into the Problems window, one of "Error", "Warning", "Information", and "Trace". The "Warning" level implicitly includes "Error"; "Information" implicitly includes "Warning" and "Error"; "Trace" includes all messages. |
openFilesOnly | true | When true, shows only errors and warnings for open files rather than for the entire workspace. |
symbolsHierarchyDepthLimit | 10 | Limits the depth of the symbol tree in the document outline. |
typeshedPaths | [] | Paths to look for typeshed modules on GitHub. |
The disabled
, errors
, warnings
, and information
settings can contain the following values:
Value | Default type | Description or message text |
---|---|---|
inherit-non-class | Warning | Attempted to inherit something that is not a class. |
too-many-function-arguments | Warning | Too many arguments have been provided to a function call. |
too-many-positional-arguments-before-star | Warning | Too many arguments have been provided before a starred argument. |
no-cls-argument | Warning | First parameter in a class method must be cls. |
no-method-argument | Warning | Method has no arguments. |
no-self-argument | Warning | First parameter in a method must be self. |
parameter-already-specified | Warning | A argument with this name has already been specified. |
parameter-missing | Warning | A required positional argument is missing. |
positional-argument-after-keyword | Warning | A positional argument has been provided after a keyword argument. |
positional-only-named | Warning | A positional-only argument (3.8+) has been named in a function call. |
return-in-init | Warning | Encountered an explicit return in __init__ function. |
typing-generic-arguments | Warning | An error occurred while constructing Generic . |
typing-typevar-arguments | Warning | An error occurred while constructing TypeVar . |
typing-newtype-arguments | Warning | An error occurred while constructing NewType . |
unknown-parameter-name | Warning | The keyword argument name provided is unknown. |
unresolved-import | Warning | An import cannot be resolved, and may be missing. |
undefined-variable | Warning | A variable has been used that has not yet been defined. |
variable-not-defined-globally | Warning | A variable is not defined in the global scope. |
variable-not-defined-nonlocal | Warning | A variable is not defined in non-local scopes. |
To suppress the "undefined-variable" messages, for example, use the setting "python.analysis.disabled": ["undefined-variable"]
. To suppress those messages and "too-many-function-arguments" messages as well, use the setting "python.analysis.disabled": ["undefined-variable", "too-many-function-arguments"]
. You can similarly set "python.analysis.errors"
, "python.analysis.warnings"
, and "python.analysis.information"
to control the visibility and severity of the diagnostics.
Setting (python.autoComplete.) | Default | Description | See also |
---|---|---|---|
addBrackets | false | Specifies whether VS Code automatically adds parentheses (() ) when autocompleting a function name. | Editing |
extraPaths | [] | Specifies locations of additional packages for which to load autocomplete data. | Editing |
Setting (python.formatting.) | Default | Description | See also |
---|---|---|---|
provider | "autopep8" | Specifies the formatter to use, either "autopep8", "black", or "yapf". | Editing - Formatting |
autopep8Path | "autopep8" | Path to autopep8 | Editing - Formatting |
autopep8Args | [] | Arguments for autopep8, where each top-level element that's separated by a space is a separate item in the list. | Editing - Formatting |
blackPath | "black" | Path to black | Editing - Formatting |
blackArgs | [] | Arguments for black, where each top-level element that's separated by a space is a separate item in the list. | Editing - Formatting |
yapfPath | "yapf" | Path to yapf | Editing - Formatting |
yapfArgs | [] | Arguments for yapf, where each top-level element that's separated by a space is a separate item in the list. | Editing - Formatting |
Setting (python.sortImports.) | Default | Description | See also |
---|---|---|---|
path | "" | Path to isort script | Editing - Refactoring - Sort Imports |
args | [] | Arguments for isort, each argument as a separate item in the array. | Editing - Refactoring - Sort Imports |
Setting (python.linting.) | Default | Description | See also |
---|---|---|---|
enabled | true | Specifies whether to enable linting in general. | Linting |
lintOnSave | true | Specifies whether to line when saving a file. | Linting |
maxNumberOfProblems | 100 | Limits the number of linting messages shown. | Linting |
ignorePatterns | [".vscode/*.py", "**/site-packages/**/*.py"] | Exclude file and folder patterns. | Linting |
Setting (python.linting.) | Default | Description | See also |
---|---|---|---|
pylintEnabled | true | Specifies whether to enable Pylint. | Linting |
pylintArgs | [] | Additional arguments for Pylint, where each top-level element that's separated by a space is a separate item in the list. | Linting |
python.linting.pylintUseMinimalCheckers | true | Specifies whether to use the default value for pylintArgs. | Linting |
pylintPath | "pylint" | The path to Pylint. | Linting |
pylintCategorySeverity.convention | "Information" | Mapping for Pylint convention message to VS Code type. | Linting |
pylintCategorySeverity.refactor | "Hint" | Mapping for Pylint refactor message to VS Code type. | Linting |
pylintCategorySeverity.warning | "Warning" | Mapping for Pylint warning message to VS Code type. | Linting |
pylintCategorySeverity.error | "Error" | Mapping for Pylint error message to VS Code type. | Linting |
pylintCategorySeverity.fatal | "Error" | Mapping for Pylint fatal message to VS Code type. | Linting |
Setting (python.linting.) | Default | Description | See also |
---|---|---|---|
pycodestyleEnabled | false | Specifies whether to enable pycodestyle. | Linting |
pycodestyleArgs | [] | Additional arguments for pycodestyle, where each top-level element that's separated by a space is a separate item in the list. | Linting |
pycodestylePath | "pycodestyle" | The path to pycodestyle. | Linting |
pycodestyleCategorySeverity.W | "Warning" | Mapping for pycodestyle W message to VS Code type. | Linting |
pycodestyleCategorySeverity.E | "Error" | Mapping for pycodestyle E message to VS Code type. | Linting |
Setting (python.linting.) | Default | Description | See also |
---|---|---|---|
flake8Enabled | false | Specifies whether to enable flake8. | Linting |
flake8Args | [] | Additional arguments for flake8, where each top-level element that's separated by a space is a separate item in the list. | Linting |
flake8Path | "flake8" | The path to flake8. | Linting |
flake8CategorySeverity.F | "Error" | Mapping for flake8 F message to VS Code type. | Linting |
flake8CategorySeverity.E | "Error" | Mapping for flake8 E message to VS Code type. | Linting |
flake8CategorySeverity.W | "Warning" | Mapping for flake8 W message to VS Code type. | Linting |
Setting (python.linting.) | Default | Description | See also |
---|---|---|---|
mypyEnabled | false | Specifies whether to enable mypy. | Linting |
mypyArgs | ["--ignore-missing-imports", "--follow-imports=silent"] | Additional arguments for mypy, where each top-level element that's separated by a space is a separate item in the list. | Linting |
mypyPath | "mypy" | The path to mypy. | Linting |
mypyCategorySeverity.error | "Error" | Mapping for mypy error message to VS Code type. | Linting |
mypyCategorySeverity.note | "Information" | Mapping for mypy note message to VS Code type. | Linting |
Setting (python.linting.) | Default | Description | See also |
---|---|---|---|
pydocstyleEnabled | false | Specifies whether to enable pydocstyle. | Linting |
pydocstyleArgs | [] | Additional arguments for pydocstyle, where each top-level element that's separated by a space is a separate item in the list. | Linting |
pydocstylePath | "pydocstyle" | The path to pydocstyle. | Linting |
Setting (python.linting.) | Default | Description | See also |
---|---|---|---|
prospectorEnabled | false | Specifies whether to enable prospector. | Linting |
prospectorArgs | [] | Additional arguments for prospector, where each top-level element that's separated by a space is a separate item in the list. | Linting |
prospectorPath | "prospector" | The path to prospector. | Linting |
Setting (python.linting.) | Default | Description | See also |
---|---|---|---|
pylamaEnabled | false | Specifies whether to enable pylama. | Linting |
pylamaArgs | [] | Additional arguments for pylama, where each top-level element that's separated by a space is a separate item in the list. | Linting |
pylamaPath | "pylama" | The path to pylama. | Linting |
Setting (python.testing.) | Default | Description | See also |
---|---|---|---|
cwd | null | Specifies an optional working directory for tests. | Testing |
promptToConfigure | true | Specifies whether VS Code prompts to configure a test framework if potential tests are discovered. | Testing |
debugPort | 3000 | Port number used for debugging of unittest tests. | Testing |
autoTestDiscoverOnSaveEnabled | true | Specifies whether to enable or disable auto run test discovery when saving a test file. | Testing |
Setting (python.testing.) | Default | Description | See also |
---|---|---|---|
unittestEnabled | false | Specifies whether unittest is enabled for testing. | Testing |
unittestArgs | ["-v", "-s", ".", "-p", "*test*.py"] | Arguments to pass to unittest, where each top-level element that's separated by a space is a separate item in the list. | Testing |
Setting (python.testing.) | Default | Description | See also |
---|---|---|---|
pytestEnabled | false | Specifies whether pytest is enabled for testing. | Testing |
pytestPath | "py.test" | Path to pytest. Use a full path if pytest is located outside the current environment. | Testing |
pytestArgs | [] | Arguments to pass to pytest, where each top-level element that's separated by a space is a separate item in the list. When debugging tests with pytest-cov installed, include --no-cov in these arguments. | Testing |
Setting (python.testing.) | Default | Description | See also |
---|---|---|---|
nosetestsEnabled | false | Specifies whether Nose is enabled for testing. | Testing |
nosetestPath | "nosetests" | Path to Nose. Use a full path if pytest is located outside the current environment. | Testing |
nosetestArgs | [] | Arguments to pass to Nose, where each top-level element that's separated by a space is a separate item in the list. | Testing |
The Python extension settings support predefined variables. Similar to the general VS Code settings, variables use the ${variableName} syntax. Specifically, the extension supports the following variables:
${cwd} - the task runner's current working directory on startup
${workspaceFolder} - the path of the folder opened in VS Code
${workspaceRootFolderName} - the name of the folder opened in VS Code without any slashes (/)
${workspaceFolderBasename} - the name of the folder opened in VS Code without any slashes (/)
${file} - the current opened file
${relativeFile} - the current opened file relative to workspaceFolder
${relativeFileDirname} - the current opened file's dirname relative to workspaceFolder
${fileBasename} - the current opened file's basename
${fileBasenameNoExtension} - the current opened file's basename with no file extension
${fileDirname} - the current opened file's dirname
${fileExtname} - the current opened file's extension
${lineNumber} - the current selected line number in the active file
${selectedText} - the current selected text in the active file
${execPath} - the path to the running VS Code executable
For additional information about predefined variables and example usages, see the the Variables reference in the general VS Code docs.
联系客服