because pycharm Once opened, the corresponding... Will be activated automatically python Virtual environment for , I mistakenly thought that all compilers would do this , And I've been using vscode More , Find out , It doesn't seem to be able to automatically activate the virtual environment itself , You need to configure the following .
First , Start in CSDN Search for several problems encountered in the operation of automatically activating the virtual environment :
Some say settings.json Just configure it
"terminal.integrated.shellArgs.windows": ["/k", "C:\\Virtualenv\\py3env\\Scripts\\activate"]
however vscode Tips :
This item is deprecated , Configure the default shell Our new recommendation is to #terminal.integrated.profiles.windows#
Create a terminal configuration file , And set its profile name to #terminal.integrated.defaultProfile.windows#
Default in . This operation will currently take precedence over the new profile settings , But it will change in the future .
Then I tried it and it didn't seem to work .
Anyway, I have encountered a lot BUG, But it was finally solved successfully , Don't talk much , Next, we will introduce step by step .
Some shortcut keys need to be understood , First ctrl+shift+p Ability to quickly open Settings , as follows :
ctrl+"~"(ESC The next key ) It can quickly open and close the terminal .
First ctrl+shift+p Search to open the settings and click to enter setting.json file :
And then put one of them "terminal.integrated.profiles.windows" and "terminal.integrated.defaultProfile.windows" Revised as follows :
"terminal.integrated.profiles.windows": {
"Command Prompt": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe",
"${env:windir}\\System32\\cmd.exe"
],
"args": [],
"icon": "terminal-cmd",
"color": "terminal.ansiYellow"
},
"Cmder": {
"path": "C:\\Windows\\system32\\cmd.exe",
"args": [
"/k",
"conda activate D:\\anaconda\\envs\\TF2.1"
// Corresponding modifications are required here ,conda activate + Where your virtual environment is located
],
"env": {
"CMDER_ROOT": "D:\\anaconda\\envs\\TF2.1\\Scripts\\python.exe"
// Corresponding modifications are required here , The location of your virtual environment compiler
},
"color": "terminal.ansiGreen",
"icon": "terminal-cmd"
},
},
"terminal.integrated.defaultProfile.windows": "Cmder",
After modification, restart to complete the configuration .
You can see that the virtual environment is automatically activated