无法在 VS-code 中为 Django 项目激活调试(虚拟环境中的 Django)

无法在 VS-code 中为 Django 项目激活调试(虚拟环境中的 Django)

问题描述:

我在 VS 代码中运行 Django 应用程序的调试环境时遇到问题:

I have an issue running the Debug environment for Django application in VS-code:

我的python不在虚拟环境中,而我的 Django 是.

my python is not in the virtual environment, while my django is.

因此,我随处看到的解决方案是将行 "pythonPath":"${workspaceRoot}/.venv/bin/python2.7", 添加到 launch.json 设置不适合,最终出现以下错误:

Therefore, the solution I see everywhere with adding to the launch.json settings the line "pythonPath": "${workspaceRoot}/.venv/bin/python2.7", does not fit, and I end up having the following error:

Exception has occurred: ImportError
Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? 
Did you forget to activate a virtual environment?

在应用程序上工作时,我使用以下命令启动设置环境:

When working on the application, I launch the setting environement using the following command:

.\venv\Scripts\activate.ps1

谁能帮我在launch.json文件中以正确的方式声明我的虚拟环境?

Can anyone help me out to declare my virtual environment the proper way in the launch.json file?

基于https://stackoverflow.com/的建议users/13877794/omid,我找到了解决方案:

Based on the suggestion of https://stackoverflow.com/users/13877794/omid, I was able to find the solution:

我打开命令面板,选择Python: select Interpreter,然后选择我感兴趣的工作区后,输入.\venv\Scripts\python.exe 这对我来说很好用.

I opened command palette, chose Python: select Interpreter, and then after selecting the workspace I was interested in, I typed in .\venv\Scripts\python.exe which works fine for me.