VS代码:激活(。)VENV,自动

发布于 2025-02-10 02:08:35 字数 19 浏览 0 评论 0原文

在花了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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文