visual-studio-code - 如何在 VSCode 的非 python 调试会话期间临时激活 virtualenv?
问题描述
所以......你知道那些你向另一个人解释你的问题并突然得到答案的时候吗?这是其中之一。下面是我的原始帖子,距离提交仅片刻之遥,当时我有一个想法可以解决这个问题!继续阅读...
我正在开发一个在 VSCode 中调试的基于 Electron 的项目。该代码的一部分产生了几个用 Python 编写的外部服务。这些服python
_pip
问题是我需要一种在调试会话开始时激活 virtualenv 的方法,就像在 bash shell 中启动了电子一样(我在我的 .bashrc 中激活了 virtualenv)。所以我的问题是:如何在调试会话期间激活 virtualenv?
为了完整起见,这是我当前的启动配置:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Electron Shell",
"cwd": "${workspaceFolder}/dist",
"runtimeExecutable": "${workspaceFolder}/dist/node_modules/electron/dist/electron",
"runtimeArgs": ["app.js", "--remote-debugging-port=9222"],
"protocol": "inspector",
},
{
"type": "chrome",
"request": "attach",
"name": "Attach to Electron Shell",
"port": 9222,
"webRoot": "${workspaceFolder}/src",
"timeout": 30000
}
],
"compounds": [
{
"name": "Debug Angular In Electron Shell",
"configurations": [
"Attach to Electron Shell",
"Launch Electron Shell",
]
}
]
}
解决方案
答案是只做activate
脚本正在做的事情: modifyPATH
和 unset PYTHONHOME
。像这样:
{
"type": "node",
"request": "launch",
"name": "Launch Electron Shell",
"cwd": "${workspaceFolder}/dist",
"runtimeExecutable": "${workspaceFolder}/dist/node_modules/electron/dist/electron",
"runtimeArgs": ["app.js", "--remote-debugging-port=9222"],
"protocol": "inspector",
"env": {
"PATH": "/path/to/virtualenv/folder/bin:${env:PATH}",
"PYTHONHOME": null
}
},
推荐阅读
- php - php文件无法向表中插入数据
- c++ - 没有GUI线程或命名窗口的OpenCV putText?
- python - Matplotlib 后端问题 _tkinter.TclError: no display name and no $DISPLAY environment variable
- node.js - 从嵌套对象投影平面值
- java - 如何在 netbeans 中的现有 GWT 项目中引用另一个 GWT 模块?
- c++ - C++ 使用 std::chrono 以一种很好的方式测量成员函数的执行
- c++ - 如何交换二维数组中的行或列?
- c# - 如何实例化和使用具有类列表的类?
- amazon-web-services - AWS 让我们加密通配符证书
- php - 教义:尝试访问一对多 php 时未定义的索引