Unable to import 'selenium' pylint(import-error)(解决方法)

Unable to import 'selenium' pylint(import-error) (solution)

我在 Visual Studio Code 中使用 python 3.7 完成作业时遇到此错误。我试图在之前的一些 Whosebug posts 中发表评论,但它不允许我发表评论。所以我分享了我在 post.

中找到的解决方案

在搜索解决方案后,我还使用了 this link.

中的步骤,得出了以下结果
  1. 在 python 文件所在的同一文件夹中创建虚拟环境 (venv) C:\YourFolderPathHere>python3 -m venv nameOfYourVenv
  2. 激活您的 python 虚拟环境 C:\YourFolderPathHere>nameOfYourVenv\Scripts\activate.bat
  3. 确保在此虚拟环境中安装了 selenium 和 pylint
    (nameOfYourVenv) C:\YourFolderPathHere>pip install selenium
    (nameOfYourVenv) C:\YourFolderPathHere>pip install pylint
  4. 从 cmd 启动 VS Code
    (nameOfYourVenv) C:\YourFolderPathHere>code 。

其他解决方案对我没有帮助,但这行得通,所以我希望它对您也有用。 :)

我的情况有点不同。我的 vscode 的解释器指向另一个版本的 python。 要更改 python3 解释器,请打开命令面板 (ctrl+shift+p) 并搜索 Python : Select Interpreter。现在将其更改为正确的路径,一切顺利。