简体   繁体   English

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

[英]Unable to import 'selenium' pylint(import-error) (solution)

I had this error while I was working on my assignment using python 3.7 in Visual Studio Code .我在Visual Studio Code使用python 3.7处理我的作业时遇到了这个错误。 I tried to comment in some previous stackoverflow posts but it doesn't allow me to comment.我试图在之前的一些 stackoverflow 帖子中发表评论,但它不允许我发表评论。 So I'm sharing the solution I found in this post.所以我分享我在这篇文章中找到的解决方案。

After searching for a solution I came up with the following, using also steps from this link.搜索解决方案后,我想出了以下内容,也使用链接中的步骤。

  1. Create virtual environment (venv) in the same folder your python file is located C:\\YourFolderPathHere>python3 -m venv nameOfYourVenv在 python 文件所在的同一文件夹中创建虚拟环境 (venv) C:\\YourFolderPathHere>python3 -m venv nameOfYourVenv
  2. Activate your python virtual environment C:\\YourFolderPathHere>nameOfYourVenv\\Scripts\\activate.bat激活你的 python 虚拟环境C:\\YourFolderPathHere>nameOfYourVenv\\Scripts\\activate.bat
  3. Make sure selenium and pylint are installed within this virtual environment确保在这个虚拟环境中安装了 selenium 和 pylint
    (nameOfYourVenv) C:\\YourFolderPathHere>pip install selenium (nameOfYourVenv) C:\\YourFolderPathHere>pip install selenium
    (nameOfYourVenv) C:\\YourFolderPathHere>pip install pylint (nameOfYourVenv) C:\\YourFolderPathHere>pip install pylint
  4. Launch VS Code from cmd从 cmd 启动 VS Code
    (nameOfYourVenv) C:\\YourFolderPathHere>code . (nameOfYourVenv) C:\\YourFolderPathHere>code 。

Other solutions weren't helpful for me but this worked so I hope it'll be useful for you as well.其他解决方案对我没有帮助,但这有效,所以我希望它对您也有用。 :) :)

In my case it was a bit different.就我而言,情况有点不同。 My vscode's interpreter was pointing to another version of python.我的 vscode 的解释器指向另一个版本的 python。 To change the python3 interpreter, open command palette(ctrl+shift+p) and search for, Python : Select Interpreter .要更改 python3 解释器,请打开命令面板(ctrl+shift+p)并搜索Python : Select Interpreter Now change that to the correct path and it is good to go.现在将其更改为正确的路径,就可以开始了。

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

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