为什么我的 vscode 没有在 wsl 中安装相同的库?

发布于 2025-01-19 19:36:41 字数 310 浏览 0 评论 0原文

我正在使用 wsl,它在 vscode 中运行代码非常好,并且我有通过 wsl 中的 pip 和 conda 安装的不同库,但是当我使用 vscode 本身运行该代码时,它无法识别这些库,甚至无法识别 pip 本身。 我没有其他环境。 我应该补充一点,我在基本环境中使用 conda install ...pip install ... 全局安装了软件包,并且我只有基本环境,并且通过以下方式运行我的代码code . 我还在我的 vscode 中安装了 python 和远程 wsl 扩展。

可能是什么问题?

I'm using wsl and it runs codes in vscode pretty fine and I have different libraries which I installed through pip and conda in wsl but when I run that code using vscode itself it doesn't recognize the libraries or even pip itself.
I don't have any other environment.
I should add that I installed the packages globally using conda install ... or pip install ... in base environment and I only have base environment and I run my code through code . and I also have python and remote wsl extensions installed in my vscode.

what can be the problem?

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

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

发布评论

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

评论(2

空心空情空意 2025-01-26 19:36:41

我对此没有太多个人经验,但我在 这个 Stack Overflow 问题 中发现了一些有用的信息(尽管它不使用 conda),以及 https://code.visualstudio.com/docs/remote/wsl-tutorial#_python-development

我还找到了这篇博文 有用,即使它不涵盖 WSL。

简而言之,请确保您:

  • 已在 VSCode 中安装了Python扩展(由 Microsoft 提供)。这对于能够检测和选择 Python 解释器至关重要。您没有提到这样做,所以我相信这可能是您的问题。

  • 您已经完成了此操作,但将其包括给以后可能会阅读本文的其他人 - 安装远程 - WSL 扩展(或远程开发 扩展包) VSCode。

  • 您也已经这样做了——从 WSL 发行版内部启动 VSCode。或者,您可以从 Windows 启动 VSCode,然后从命令面板(也可以从“远程”状态栏访问)中选择远程 WSL - 在 WSL 中重新打开文件夹

  • 在 VSCode 中,使用 Shift+Ctrl+P 打开命令面板,搜索Python:选择解释器 命令,您应该在列表中找到您的 Conda 环境。


选择此选项后,您应该会发现您的项目正在使用通过 conda 安装的解释器和模块。

I don't have much personal experience with this, but I found some useful information in this Stack Overflow question (even though it doesn't utilize conda), along with https://code.visualstudio.com/docs/remote/wsl-tutorial#_python-development.

I also found this blog post useful, even if it doesn't cover WSL.

In short, make sure you:

  • Have installed the Python extension (by Microsoft) in VSCode. This is critical for being able to detect and select the Python interpreter. You don't mention having this in place, so I believe this is your likely problem.

  • You have done this already, but including it for others who might read this later -- Install the Remote - WSL extension (or the Remote Development extension pack) in VSCode.

  • You are also doing this already -- Start VSCode from inside your WSL distribution. Alternatively, you can start VSCode from Windows and then select the Remote WSL - Reopen Folder in WSL from the Command Palette (also accessible from the "Remote" Status Bar).

  • In VSCode, open the Command Palette with Shift+Ctrl+P, search for the Python: Select Interpreter command, and you should find your Conda environment in the list.

After selecting this, you should find that your project is using the interpreter and modules that you have installed via conda.

善良天后 2025-01-26 19:36:41

我为解决这个问题所做的一件事是转到扩展 -> Local(那里应该有两个选项卡,Local 和 WSL:DISTRO)DISTRO 指的是您正在使用的任何 DISTRO,您会看到一些本地扩展在当前工作区 (WSL) 中被禁用,并且有一个小云图标在 WSL:DISTRO 选项卡中,显示在 WSL:DISTRO 中安装本地扩展,单击后,您将可以选择要安装的扩展,然后就可以开始了!

One thing I did to overcome this issue is go to Extensions -> Local (You should have two tabs there, Local and WSL:DISTRO) DISTRO refers to whatever DISTRO you're using, you will see that some of the local extensions are disabled in the current workspace (WSL) and there is a little cloud icon in the WSL:DISTRO tab that says install Local Extensions in WSL:DISTRO once you click that it will let you choose which extensions to install and you should be good to go!

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