vscode uses virtual environment

My conda is not added to the path, and it always reports an error every time I open it.

1. Select the interpreter corresponding to the virtual environment

1. Click here in the lower right corner of vscode

 2. After clicking, the following picture may appear above vscode. If the following picture appears, click the second item Select at workspace level.

 3. Then the following picture style appears (there may be no above picture, and the following picture style appears directly). Select the corresponding interpreter, or click Enter interpreter path and enter the location path of the interpreter you want to specify.

 If the selection is successful, the interpreter you specified will be displayed in the lower right corner.

2. Modify settings.json

To do this, first make sure you have the Code Runner plug-in installed in your vscode, because the following code changes the Code Runner running command.

Put the following content into settings.json and modify the interpreter path according to your needs . This file is located in the .vscode folder in the root directory of the folder opened by vscode. The function is to set utf-8 encoding (can print out Chinese) and specify the interpreter.

"code-runner.executorMap":{
    //"python":"set PYTHONIOENCODING=utf8 && python"
    "python":"set PYTHONIOENCODING=utf8 && D:\\Anaconda3\\envs\\env_pytorch\\python.exe" 
}, 

 If you get an error after putting it in, it may be that there is no comma at the end of the previous item at the location you pasted, because commas need to be separated between items.

 

If there is no settings.json file in your .vscode folder , you can manually create settings.json in .vscode and directly copy the following code into it

{
"code-runner.executorMap":{
    //"python":"set PYTHONIOENCODING=utf8 && python"
    "python":"set PYTHONIOENCODING=utf8 && D:\\Anaconda3\\envs\\env_pytorch\\python.exe" 
}, 

}

おすすめ

転載: blog.csdn.net/qq_35858902/article/details/130329425