简体   繁体   中英

I have installed all the python libraries i want to use in the vscode terminal but when i call to import, it won't work

[{
    "resource": "/d:/Users/Home/Desktop/Python/estudos/pratices.py",
    "owner": "_generated_diagnostic_collection_name_#0",
    "code": {
        "value": "reportMissingModuleSource",
        "target": {
            "$mid": 1,
            "external": "https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportMissingModuleSource",
            "path": "/microsoft/pyright/blob/main/docs/configuration.md",
            "scheme": "https",
            "authority": "github.com",
            "fragment": "reportMissingModuleSource"
        }
    },
    "severity": 4,
    "message": "Import \"pandas\" could not be resolved from source",
    "source": "Pylance",
    "startLineNumber": 1,
    "startColumn": 8,
    "endLineNumber": 1,
    "endColumn": 14
}]

is the message given the cmd shell tells me i have all the libraries i want installed and they're in the project folder, i'm running a virtual environment but whenever i try to run something in a.py file, it says that it's not defined, i have installed anaconda but don't mean to use it right now, if i open a jupyter file it'll import no problem, but trying to run pip doesn't work at all

reinstalling vscode, making sure python's installed, making sure pip is installed

I had a similar issue before and the solution I found is that you have to make sure the python interpreter for the current VSC window is your virtual environment instead of the system-wide python interpreter. On windows:

  • Press F1
  • Search for "interpreter".
  • Click the python one
  • Click "Enter interpreter path".
  • Finally locate your virtual environment.

You should make sure that the current interpreter and the pandas library installed are the same interpreter environment.

The current interpreter can be output with the following code.

import sys
print(sys.executable)

Then install the pandas library with the resulting interpreter path.

<the path obtained above> -m pip install pandas

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM