【发布时间】:2018-02-07 01:16:30
【问题描述】:
我回答了我自己的问题,请参阅下面的解决方案。将这一切留给后代,因为我做了很多其他人说会工作并且为他们工作的事情,但没有一个工作。
问题
下面是一个非常简单的python文件。当试图在这个文件上使用 Visual Studio Code 的调试器时,我总是在任何内部模块上得到一个ImportError,比如app.models 或app.tests.scripts.stubs。如果这些模块在faker 或任何其他外部模块下方列出,则调试器将通过外部模块而不会引发错误,但会在app.models 或首先列出的任何内部模块上引发错误。在我尝试过的 8-10 个文件中确实如此。
我尝试过的
我已经在 launch.json 和 User Settings 中指定了确切的 pythonPath,如下所示。我添加了"exceptionHandling" 以忽略 ImportErrors。我已经卸载并重新安装了 Don Jayamanne 出色的 Python 扩展。我已经运行了Python: Select Workspace Interpreter 并将其指向./.venv/bin/python2.7、./.venv/bin/python2 和``./.venv/bin/python`。
文件
launch.json Python 配置
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "/Users/REDACTED/REDACTED/.venv/bin/python2.7",
"program": "${file}",
"cwd": "${workspaceRoot}",
"env": null,
# we have 10+ environmental shell scripts, so I can't really use "envFile" in
# a meaningful way, though I have tried pointing it at one of the shell scripts
# but was still unable to debug.
"envFile": "${workspaceRoot}/.venv",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
],
"exceptionHandling": {
"ignore": [
"ImportError"
]
}
},
Python 文件
from app.models import Kelly
import app.tests.scripts.stubs
from faker import Faker
import factory
from datetime import datetime
from bson.objectid import ObjectId
fake = Faker()
kelly_names = [REDACTED]
class KellyFactory(factory.Factory):
class Meta:
model = Kelly
id = ObjectId()
is_archived = False
email = factory.LazyAttribute(
lambda kel: '%s@email.com' % kel.name.split()[0])
name = fake.word(ext_word_list=kelly_names)
phone = fake.phone_number()
date_last_modified = datetime.now()
kelly = KellyFactory()
【问题讨论】:
标签: python-2.7 visual-studio-code visual-studio-debugging vscode-settings