如何使VSCODE集成的终端虚拟环境正常工作?

发布于 2025-01-28 20:17:06 字数 807 浏览 3 评论 0原文

我已经在Python在线完成了一些课程,最近在Django开设了一门新课程。以前,我一直使用虚拟环境,但会自己激活环境,但是在课程中,我正在通过用mosh 代码他显示了一种使VSCODE在终端中自动激活环境的方法。

我试图跟随,但很难使它工作。首先,我尝试按照Mac上的终端位置位置,使用:pipenv -venv尝试按照MOSH的步骤进行操作,然后将位置返回为/users/lewpiper/.local/.local/share/share/virtualenvs /Mac上的/店面7uylletm。然后,我试图在vscode中路径末端的bin/python中使用它在命令调色板中使用它,以选择Python解释器,并且似乎不起作用。看来它没有创建我在观看的课程中看到的Vscode文件夹或JSON文件。

然后,我尝试在vscode中编辑工作区设置,并添加以下“ python.pythonpath”:“/users/lewpiper/.local/share/share/virtualenvs/storefront-7uylletm" <同样,我遇到了它并没有通过激活虚拟环境来启动终端窗口。

现在,当我单击VSCODE播放时,我会收到以下消息“ Importerror:无法导入Django。您确定它已安装并在您的PythonPath环境变量上使用吗?您是否忘记了激活虚拟环境?”

任何帮助或指导我朝正确方向指导我的帮助或指导将不胜感激。

I have completed a few courses online in Python and recently started a new course in Django. Previously I always used a virtual environment but would activate the environment myself, but in the course I am working through via Code with Mosh he shows a way to have VSCode activate the environment automatically in the terminal.

I tried to follow along but am having a hard time getting this to work. First I tried following Mosh’s steps by locating the virtual environment location in terminal on the Mac using: pipenv --venv and this returned the location as /Users/lewpiper/.local/share/virtualenvs/storefront-7UYLLetM on my Mac. I then tried to to use this in the command palette with bin/python on the end of the path in VSCode to select the python interpreter and it didn’t seem to work. It seems like it didn't create the VSCode folder or JSON file that I saw in the lessons I was watching.

Then I tried to edit the workspace settings in VSCode and add the following "python.pythonPath": "/Users/lewpiper/.local/share/virtualenvs/storefront-7UYLLetM"to match the VSCode file structure and again I am running into it not launching the terminal window with the virtual environment activated.

Now when I click play in VSCode I get the following message “ImportError: Couldn’t import Django. Are you sure it’s installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?”

Any help or direction to guide me in the right direction would be very much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

失退 2025-02-04 20:17:06

我意识到了我的问题并将其阅读给自己,我从未在JSON文件中的路径结束时添加/bin/python。修复了它。

I realized after writing my question out and reading it back to myself that I never added /bin/python to the end of the path in the JSON file. That fixed it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文