简体   繁体   中英

"ImportError: No module named selenium" on VSCode

I'm making a project with selenium, and the following error is disturbing me. I'm using VSCode with Code Runner, and my OS is Ubuntu 20.04:

[Running] python -u "/home/albomonco/Desktop/forca.py"
Traceback (most recent call last):
  File "/home/albomonco/Desktop/forca.py", line 1, in <module>
    from selenium import webdriver
ImportError: No module named selenium

[Done] exited with code=1 in 0.028 seconds

I have installed Firefox geckodriver on github, and I have put geckodriver to my PATH in /usr/bin and in /usr/local/bin using "sudo cp /geckodriver/path /usr/bin". I have already done "pip3 install selenium".

What is really weird is that if I go to Terminal, and run "python3 name_of_file.py", it works. I have searched a lot, and I didn't found anything about it. I also tested on IDLE IDE, and it worked fine.

Try this answer of Raj Dhaker

Uninstall Selenium using pip uninstall selenium Then create a New Folder on your preferred location, (Like Desktop, or D drive, etc.) Open that folder in Visual Studio Code.Now go to the Terminal of VS Code and create a Virtual Environment (Google python Virtual Environment if you don't know how to create one) Then, install selenium in that virtual Environment using pip install selenium You will see some files are included in your folder after pip install selenium ( pipfile and pipfile.lok ) Lastly, install pyLint to your virtual environment using pipenv install pylint --dev

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