简体   繁体   English

导入模块无法解析

[英]Import module could not be resolved

I've successfully installed "PyPDF2" module and checked it using the command 'pip list'.我已经成功安装了“PyPDF2”模块并使用命令“pip list”对其进行了检查。 yet when I try to import it i receive this message: '''Import "PyPDF2" could not be resolved'''然而,当我尝试导入它时,我收到此消息:'''Import "PyPDF2" could not besolved''' 在此处输入图像描述

The version of python that you installed the module in and the version that your IDE is using might be different check what version you installed it in by typing您安装模块的 python 版本和您的 IDE 使用的版本可能不同,通过键入检查您安装它的版本

pip -VV

in your terminal and check in what version your IDE is using (for vs code its usually shown at the bottom left or can be seen in the command pallete by typing Python: Select Interpreter )在您的终端中检查您的 IDE 使用的版本(对于 vs 代码,它通常显示在左下角,或者可以通过键入Python 在命令面板中看到:选择解释器

another reason this could happen is if you are using an IDE like pycharm which by default creates a virtual environment for each project in which case you would need to either install your module from pycharm's terminal or activate the virtual environment and then install in it (docs here show how to https://docs.python.org/3/tutorial/venv.html )发生这种情况的另一个原因是,如果您使用像 pycharm 这样的 IDE,默认情况下会为每个项目创建一个虚拟环境,在这种情况下,您需要从 pycharm 的终端安装模块或激活虚拟环境,然后在其中安装(文档这里展示如何https://docs.python.org/3/tutorial/venv.html

  1. Make sure you have installed PyPDF2确保您已安装 PyPDF2
pip install PyPDF2
  1. Select the correct interpreter选择正确的口译员

Click点击

First of all, please make sure that you are using the correct environment and python interpreter.首先,请确保您使用的是正确的环境和 python 解释器。 If multiple python versions exist on your computer, use the command to install the PyPDF2 package under the version you need.如果您的计算机上存在多个 python 版本,请使用命令将 PyPDF2 包安装到您需要的版本下。 For example python3:例如python3:

py -3 -m pip install PyPDF2

Another possible reason: Paths are not imported correctly.另一个可能的原因:路径未正确导入。 Please add the following commands in the setting.json file:请在 setting.json 文件中添加以下命令:

"python.analysis.extraPaths":[
    // The folder path where the custom module is located, and multiple paths can be added (the following is just an example)
    // absolute path
    "c:\\workspace\\pythontest\\.venv\\lib\\site-packages",
    "E:\\myfolder\\homework\\one\\Person_reID_baseline_pytorch-master",
    // relative path
    "./src",
    "./modules" 
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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