Vscode-code-runner: How to switch between different version of Python conveniently

Created on 26 Jun 2017  ·  8Comments  ·  Source: formulahendry/vscode-code-runner

因为日常有用到多种环境,所以我的环境有python2.7,python3.5,python3.6 多版本共存。如果采用vscode的python ‘env’配置,可以正常切换
image
但是用插件,感觉只能指定一种版本,不能随意选择切换,能否可以扩展下?或者可以读取vscode 中的"python.pythonPath" 路径,这样就可以随意切换了。

enhancement help wanted

Most helpful comment

Now, the latest Code Runner could respect the python path set by 'Python: Select Interpreter', please update with below setting and have a try:

"code-runner.executorMap": {
    "python":"$pythonPath $fullFileName"
}

All 8 comments

You could set path for Python in Workspace setting (File->Preference->Settings->Workspace settings):

{
    "code-runner.executorMap": {
        "python": "python_path"
    }
}

这个只能指定具体的某个版本吧,不能够随意切换,每次运行不同的版本脚本,就要修改一次版本的路径,这样切换感觉很麻烦呀!有没有好的解决方案呀?

I don't understand non-English words so sorry if I'm repeating what's already been said:

Don Jayamanne's Python extension makes it very easy to change workspace interpreter to some wanted env (as shown in the screenshot in the original post).
Is there a way for Coder Runner to automatically change to use env's Python to run the code? If there is no such thing - could this be added in some future version?

@narimiran I will take a look at the user experience of this.

确实,希望能够和Python的"python.pythonPath"配置结合~或者借鉴它的思维

Maybe it is better to respect python.pythonPath? So user can change python version conveniently

@WLswert you can use virtualenv under the project root and set path like this:

"code-runner.executorMap": {
    "python": ".env/bin/python"
}

So the interpreter of code-runner will according to the python version of virtualenv.

Now, the latest Code Runner could respect the python path set by 'Python: Select Interpreter', please update with below setting and have a try:

"code-runner.executorMap": {
    "python":"$pythonPath $fullFileName"
}
Was this page helpful?
0 / 5 - 0 ratings