我想在Visual Studio Code中调试用python3编写的项目,但我似乎找不到在launch.json文件中指定解释器或python版本的任何方法。
它适用于Python 2,所以问题是,如何让它适用于Python 3?
答案 0 :(得分:31)
由于我无法对接受的答案发表评论,因此我会将部分answer复制到类似的问题中。
截至2016年9月(根据扩展的Github repo文档),您只需从vscode中执行一个命令,该命令将允许您从自动生成的已知解释器列表中选择解释器(包括项目中的解释器和#) 39;虚拟环境)。
执行:
Python: Select Workspace Interpreter
更新此命令已更新为:
Python: Select Interpreter
命令托盘中的(适用于Windows的F1,适用于MacOS的Ctrl + Shift + P)。
然后选择下拉列表中显示的一个python解释器。就是这样。您的settings.json将自动编辑,指向您选择的解释器。
答案 1 :(得分:21)
Python3调试也很有效。这有点令人困惑,因为指定路径有两个不同的位置: settings.json 和 launch.json 。我建议使用Don Jayamanne's Python Extension。安装后,您必须configure the path到要使用它的解释器。
用于Intellisense,Autocomplete,Linting,Formatting等的Python版本
同样的python解释器用于智能感知,自动完成, linting,格式化等(除调试之外的一切)。该 使用的标准解释器是第一个" python"翻译员 在当前路径中遇到。如果要使用其他版本, 这可以通过以下两种方式之一进行配置:
在“用户设置”文件中配置python解释器的路径 (settings.json)如下。确保指定完全限定名称 python可执行文件。 " python.pythonPath&#34 ;: " C:/python27/python.exe"
配置python解释器的路径 在工作区设置文件(settings.json)中,如下所示。确保 指定python可执行文件的完全限定名称。 " python.pythonPath":" c:/python27/python.exe"用于的Python版本 调试
可在此处找到有关调试配置设置的详细信息 调试。只需提供python的完全限定路径即可 可执行的" python"在配置设置中进行设置 在launch.json文件中如下:
{
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"program": "${file}",
"pythonPath": "c:/python27/python.exe",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
] }
答案 2 :(得分:2)
设置文件中有一个设置触发器:
表示python默认值(现在为2.7)
"python.pythonPath": "python",
for python3:
"python.pythonPath": "python3",
使用follow命令检查python版本:
import sys
print(sys.version)
答案 3 :(得分:2)
我们可以在 settings.json 中的python3中配置调试:
文件>首选项>设置(〜/ .config / Code / User / settings.json)[用户设置]
{
...
"python.pythonPath": "python3",
}
还要验证 launch.json 文件已经具有以下配置:
"configurations": [
{
"name": "Python: Current File (Integrated Terminal)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
},
...
]
答案 4 :(得分:1)
通过连续统计分析使用anaconda python发行版的人员的额外注意事项;你可能会发现我的经验很有用。
我正在使用Don Jayamanne的Python扩展程序并运行" Select Workspace Interpreter"命令,但仍然发现我正在为错误的python版本提供建议。
对我有用的修复方法是为anaconda安装pylint包。
12:05:22,592 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-5) MSC000001: Failed to start service jboss.deployment.subunit."client-ear-0.0.1-SNAPSHOT.ear"."client-ejb-0.0.1-SNAPSHOT.jar".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.subunit."client-ear-0.0.1-SNAPSHOT.ear"."client-ejb-0.0.1-SNAPSHOT.jar".INSTALL: WFLYSRV0153: Failed to process phase INSTALL of subdeployment "client-ejb-0.0.1-SNAPSHOT.jar" of deployment "client-ear-0.0.1-SNAPSHOT.ear"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:154)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYEE0052: Failed to install component DummyClient
at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.deploy(ComponentInstallProcessor.java:109)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:147)
... 5 more
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYEJB0406: No EJB found with interface of type 'com.server.api.DummyApi' for binding com.client.DummyClient/dummyApi
at org.jboss.as.ejb3.deployment.processors.EjbInjectionSource.getResourceValue(EjbInjectionSource.java:90)
at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.processBindings(ComponentInstallProcessor.java:263)
at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.access$000(ComponentInstallProcessor.java:80)
at org.jboss.as.ee.component.deployers.ComponentInstallProcessor$1.handle(ComponentInstallProcessor.java:215)
at org.jboss.as.ee.component.ClassDescriptionTraversal.run(ClassDescriptionTraversal.java:54)
at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.deployComponent(ComponentInstallProcessor.java:218)
at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.deploy(ComponentInstallProcessor.java:101)
... 6 more
答案 5 :(得分:0)
要在Visual Studio Code中调试Python项目,请使用启动配置,如下所示:
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${cwd}/{filename}.py",
"args" : [
"--arg1", "arg1-value",
"--arg2", "arg2-value",
"--arg3", "arg3-value"
],
"console": "integratedTerminal"