简体   繁体   English

如何在 Visual Studio Code 中开始调试 Python 3.6?

[英]How to start debugging Python 3.6 in Visual Studio Code?

I'm trying to create some script using this IDE but I can't make it work.我正在尝试使用此 IDE 创建一些脚本,但无法使其工作。 I installed Python 3.6, added to path (it's visible finally), installed Python extension (from Microsoft I believe).我安装了 Python 3.6,添加到路径(最终可见),安装了 Python 扩展(我相信来自 Microsoft)。

Then I tried this manual https://code.visualstudio.com/docs/python/environments but I'm stuck on the first step.然后我尝试了这个手册https://code.visualstudio.com/docs/python/environments但我被困在了第一步。

When I try the command Select Workspace interpreter I have the following error:当我尝试命令 Select Workspace interpreter 时,出现以下错误:

command 'python.setInterpreter' not found找不到命令“python.setInterpreter”

I'm puzzled what it means.我很困惑这是什么意思。 Google can't find anything on this issue, only some github pages that don't exist anymore.谷歌在这个问题上找不到任何东西,只有一些不再存在的github页面。

And if I try to start debugging it shows:如果我尝试开始调试,它会显示:

command 'python.python-debug.startSession' not found未找到命令“python.python-debug.startSession”

OS: Windows 7 Also I want to test scripts created in virtual environment, maybe it's a reason why it doesn't work but I have no idea how to do it.操作系统:Windows 7 另外我想测试在虚拟环境中创建的脚本,也许这是它不起作用的原因,但我不知道如何去做。

UPD: I uninstalled and installed the extension again. UPD:我再次卸载并安装了扩展程序。 I don't see these error but debugging still doesn't work just loading CPU and ignoring any breakpoints.我没有看到这些错误,但调试仍然无法正常工作,只是加载 CPU 并忽略任何断点。

它对我~/.vscode/extensions/ ,进入~/.vscode/extensions/ ,手动删除扩展的文件夹并重新安装。

In vscode do the following...在 vscode 中执行以下操作...

  1. ctrl + shift + p
  2. Select Python: Create Terminal .选择Python: Create Terminal this should get rid of "command 'python.setInterpreter' not found" problem这应该摆脱“找不到命令'python.setInterpreter'”问题
  3. ctrl + shift + p
  4. Select Python: Select Interpreter选择Python: Select Interpreter
  5. Select the path to your virtual environment folder.选择虚拟环境文件夹的路径。 This will now create a .vscode folder in the root directory of your folder and the settings file with "python.pythonPath": "venv\\\\Scripts\\\\python.exe" in it现在,这将在文件夹的根目录中创建一个 .vscode 文件夹,并在其中创建带有"python.pythonPath": "venv\\\\Scripts\\\\python.exe"的设置文件
  6. You might get "Linter pylint not installed" notification at the bottom您可能会在底部收到“未安装 Linter pylint”通知
  7. Run pip install -U pylint运行pip install -U pylint
  8. Open a document and you should not see the notification anymore打开一个文档,你应该不会再看到通知了

One way to tackle this problem in Visual Studio Code is to the downgrade the version of Python extension from Microsoft.在 Visual Studio Code 中解决此问题的一种方法是从 Microsoft 降级 Python 扩展的版本。 It can be very easily done through the Visual Studio Code interface.它可以通过 Visual Studio Code 界面轻松完成。 Locate the installed extension using the extension tab, and right click on the extension.使用扩展选项卡找到已安装的扩展,然后右键单击扩展。 Then You will find an option "Install Another Version...".然后你会发现一个选项“安装另一个版本......”。 Click on that and you will find a bunch of versions.点击它,你会发现一堆版本。 Select the one that was published, for example, a month ago.选择发布的,例如,一个月前。 Try to see if it works.尝试看看它是否有效。 If it does not, try with the other (preferably older) ones.如果没有,请尝试使用其他(最好是较旧的)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM