How can I launch an exe within a conda env

徘徊边缘 提交于 2019-12-21 16:36:07

问题


I'm using vscode in Windows 10 as my code editor, and want to make an easy way to launch it with the correct conda env to allow debugging.

Currently I am having to open a command prompt, then activate the conda env, then paste the shortcut to vscode into the prompt to execute. Like so:

cmd
activate env-name
"C:\Program Files (x86)\Microsoft VS Code\Code.exe"

I have tried creating a batch file to wrap these calls, but unfortunately once I call "source activate" to start the conda env, the batch commands after this are not executed as it is considered another instance.

Any tips? Other than writing a vscode extension to handle this (which I'm seriously tempted to do, but it's such a simple problem...)


回答1:


You might want to run source activate env-name as a task in visual studio. https://code.visualstudio.com/Docs/editor/tasks

tasks.json

{
    "version": "0.1.0",
    "command": "cmd",
    "isShellCommand": true,
    "suppressTaskName": true,
    "args": [],
    "tasks": [
        {
            "taskName": "development",
            "args": ["source", "activate", "env-name"]
        }
    ]
}



回答2:


The best option I found is to set the python.venvPath parameter in vscode settings to your anaconda envs folder.

"python.venvPath": "/Users/[...]/Anaconda3/envs"

Then if you bring up the command palette (ctl + shift + P on windows/linux, cmd + shift + P on mac) and type Python: Select Workspace Interpreter all your envs will show up and you can select which env to use.

The python extension will also need to be installed for the Select Workspace Interpreter option.

Note: The Select Workspace Interpreter takes around 10 seconds to come up on my computer using the current version of VSCode. My answer was originally posted here.



来源:https://stackoverflow.com/questions/37199846/how-can-i-launch-an-exe-within-a-conda-env

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!