簡體   English   中英

導入 python 在我的 Linux 終端上工作,但在 VS 代碼上引發 ModuleNotFoundError

[英]import in python working on my Linux Terminal but raising ModuleNotFoundError on VS code

我是 Linux 的新手,因為我最近才開始使用它。 我安裝了不同的庫,如 numpy、pandas 等。 import numpy as np import pandas as pd它在 VS Code 中引發了 ModuleNotFoundError。 但是當我在終端中運行相同的代碼時,就沒有問題了。 注意:我使用pip3 install package安裝了這些庫 OS: Ubuntu 22.04

我嘗試卸載 package 並重新安裝,但仍然無法正常工作。 我還嘗試通過sudo apt-get install python3-pandas 什么都行不通。

沒有所有上下文,聽起來您有幾個不同的 python 環境。

在終端中檢查您正在使用which python在 VSCode 設置中檢查Python: Default Interpreter Path

這可能會幫助您了解正在發生的事情。 確保 VSCode python 路徑與您的終端打印出的路徑相同。

看來你有兩個或更多 python 的解釋器。

您可以使用快捷鍵“Ctrl+Shift+P ”並輸入“Python: Select Interpreter”來在 VsCode 中選擇正確的 python 解釋器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM