visual studio code - Automatically switch VSC venvinterpreter depending on selected folder - Stack Overflow

My query is while switching projects how we change python interpreter to that specific project .venv sh

My query is while switching projects how we change python interpreter to that specific project .venv shown in bottom right & the (.venv) in terminal?

Situation

I have project1 with .env1 as venv I created a new folder via windows explorer project2 and redirected to it in vs terminal, initialized it, created new venv for it named .env2. VSCode asked me whether I want to set default intrepretor for this workspace, when I clicked yes, it changed the interpreter from 3.12 (.env1) to 3.12 (.env2). Now I have both projects folder in a single view in VSCode. and I am working on proj1, Intrepretor (.env1) & Terminal have (.env) activated. Now I want to simultaneously work on proj2. When opening the Project 2 file the path dynamically changes in terminal however the Venv and intrepretor remains the same which are not of that project2.

I have set my terminal.intergrated.cwd as ${filedirname} this helps to dynamically change terminal path to specific project path who's file I opened. I have also Made this setting "python.terminal.activateEnvironment": true.
But the (.env1) in terminal remains same. i.e (.env1) project2. What about change to environment in terminal. It should also be from (.env1)project1path to (.env2)project2path. In the same way, the interpreter remain the same and not change dynamically with change in file. Shouldn't the interpreter change automatically in such case as i am switching projects itself which have different interpreter, different path and different venvs.

Attempted solutions

A. Manually deactivate old venv and activate new venv. I want it to be auto detected as it does when we open the VScode. but it doesn't chnage it automatically when we switch between projects.

B. Using multiroot workspace concept. But not sure it will help to change the venv and interpreter automatically to that respective project Or it's just to see two projects in one window nothing much

C. use of .vscode/settings json file which we can add for specific folder. but not sure can it be created for every folder or only for folders inside a workspace

D. Following rule of opening different projects in different VScode window with that specific intrepretor selected and activated in terminal all manually by juggling between projects

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744692947a4588317.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信