VS代码:激活(。)VENV,自动
在花了5-6个小时试图用我自己的
After spending 5-6 hours trying to figure it out on my own ????, turning to the community for help.
I have been using VS Code for a couple years with Python on a Mac Mini (100+ projects).
Now migrated to a Mac Studio.
The behaviour I have on my old Mac (set up a couple years ago), is that upon opening a python script in VS Code and running it in the VS Code terminal, it automatically activates the venv (/.venv
or /venv
depending on project) and initiates by printing:
source /Users/n1c/PROJECT/.venv/bin/activate
(or source /Users/n1c/PROJECT/venv/bin/activate
depending on project)
On my new Mac, I am unable to replicate this much needed behaviour.
Furthermore, even if I manually activate (source venv/bin/activate
), it still runs with the global interpreter instead of the venv interpreter, eg
(venv) n1c@yyy test2 % /usr/bin/python3 /Users/n1c/PROJECT/test2.py
hello
Same behaviour across many projects tested.
How do I get VS Code to use the venv, and automatically activate on each run?
Notes:
- all projects have been fetched from Github to my new Mac OR just copy/pasted (including invisible files)
- VS Code Settings Sync is on, ie mirrored settings with old Mac
- in settings.json I have:
{ "python.terminal.activateEnvInCurrentTerminal": true, "python.terminal.activateEnvironment": true, }
- I have also tried (for troubleshooting purposes) in .vscode/settings.json:
{ "python.pythonPath": "/Users/n1c/PROJECT/.venv/bin/python" }
to no avail
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论