程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Teach you the vscode terminal to automatically activate Anacondas Python virtual environment

編輯:Python

List of articles

  • Preface
  • Shortcut key
  • modify settings.json file

Preface

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 .

Shortcut key

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 .

modify settings.json file

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


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved