简体   繁体   English

Visual Studio 调试 Python 交互式:未找到名为 traceback 的模块

[英]Visual Studio debug Python interactive: no module named traceback found

Probably simple error, but my current Visual Studio project is not able to run debug Python interactive.可能是简单的错误,但我当前的 Visual Studio 项目无法运行调试 Python 交互。 I had this working with same computer and environment before.我以前在相同的计算机和环境中使用过这个。

I have Python project open in Visual Studio, test with new module1.py file in project, the contents of file is just print('test output to console') .我在 Visual Studio 中打开了 Python 项目,在项目中使用新的module1.py文件进行测试,文件的内容只是print('test output to console')

Python 3.7 showing as virtual environment in the project still, as previously, I click Debug -> Execute File in Python Interactive. Python 3.7 在项目中仍然显示为虚拟环境,和以前一样,我在 Python Interactive 中单击 Debug -> Execute File。

Then it fails to run after not finding Traceback file, trace as follows:然后在找不到Traceback文件后运行失败,trace如下:

Resetting Python state.
Running C:\Users\will_\Documents\Repos\Facebook1\FacebookNonConfVersion\module1.py
Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\Extensions\Microsoft\Python\Core\ptvsd_repl_launcher.py", line 27, in <module>
    import traceback
ModuleNotFoundError: No module named 'traceback'
The interactive Python process has exited.

Also, after activating this project's Python 3.7 virtual environment in command prompt, this module1.py file will still run, so I assume that the virtual environment is not corrupted, and this error is something to do with my VS setup, but I may be wrong.另外,在命令提示符下激活这个项目的Python 3.7虚拟环境后,这个module1.py文件仍然会运行,所以我假设虚拟环境没有损坏,这个错误与我的VS设置有关,但我可能错误的。

I'm probably missing something obvious.我可能遗漏了一些明显的东西。

OK, the key info I didn't mention (if I knew to mention it, probably wouldn't have asked the question) was that I manually renamed both the Visual Studio solution and project files in Windows File Explorer, after copying the whole solution first to back it up.好的,我没有提到的关键信息(如果我知道提到它,可能不会问这个问题)是在复制整个解决方案后,我在 Windows 文件资源管理器中手动重命名了 Visual Studio 解决方案和项目文件首先备份它。

If anyone else sees this, I fixed the problem by just creating new solution and project in Visual Studio, re-installing packages I needed in virtual environment in the new solution, and copying over the Python files.如果其他人看到这一点,我只需在 Visual Studio 中创建新的解决方案和项目,在新解决方案的虚拟环境中重新安装我需要的包,然后复制 Python 文件来解决问题。

I now appreciate the VS solution file is actually a very small (1kb in my case) text file with config settings including some long hex numbers, and just renaming it in Windows file explorer will probably (certainly?) mess up all the references, and prevent it from running (actually in console mine couldn't find the openpyxl package I had installed in virtual environment, so couldn't run the main Python file, I guess because of this).我现在很欣赏 VS 解决方案文件实际上是一个非常小的(在我的情况下为 1kb)文本文件,其中包含一些长十六进制数字的配置设置,只是在 Windows 文件资源管理器中重命名它可能会(当然?)弄乱所有引用,并且阻止它运行(实际上我在控制台中找不到我在虚拟环境中安装的 openpyxl 包,所以无法运行主 Python 文件,我猜是因为这个)。

Related to this problem is canonical looking question: Proper way to rename solution (and directories) in Visual Studio与此问题相关的是规范的问题: 在 Visual Studio 中重命名解决方案(和目录)的正确方法

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

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