4

How to solve No module named 'selenium' in VS code?

Module to be used

from selenium import webdriver 
import time,sys,csv,pyautogui

However, the following error occurred.

ModuleNotFoundError: No module named 'selenium'

I tried in VS code to solve this error.

A similar situation with me, stack overflow the resolution, but failed.

-> ImportError: No module named 'selenium'

1.pip install selenium
2.conda install selenium

enter image description here -> select Python 3.8.5 -64bit(conda)

how to solved ModuleNotFoundError? help me..

comment update(programandoconro) enter image description here

-> An error still occurs.

comment update(Prophet)

enter image description here

-> An error still occurs.

Prophet
  • 32,350
  • 22
  • 54
  • 79
elk_basic
  • 153
  • 2
  • 2
  • 9
  • I see you installed Selenium but can't see you set the system PATH while this is the main problem here – Prophet Jun 11 '21 at 08:13

5 Answers5

4

Please try python3 -m pip install selenium. This will allow you to use the current active version of Python you are using.

Update:

I saw that you are using an .ipynb extension. I am not an expert in those kind of environments but I would try to run !python3 -m pip install selenium inside the file (not the terminal). This only the first time, then you can comment that line. Please try that.

programandoconro
  • 2,378
  • 2
  • 18
  • 33
3

Both answers above might work but it is better to create a virtual environment and install your dependencies in there. Since you're already using Anaconda, I'll list the steps below.

You can create a virtual environment with Anaconda:

  1. conda create -n yourenvname python=x.x anaconda
  2. source activate yourenvname

You can find more info how to setup your environment here

William
  • 352
  • 4
  • 16
2

Best Solution: Worked for me.

Issue: The version of python you are using does not have "Selenium" in its root folder. If you are using python 3.8 for instance, you are missing Selenium in "Lib\site-packages" directory.

  1. Go to your C:\ drive and locate all your Python folders (python version #s)
  2. In each folder go to "Lib\site-packages" and see if you have "Selenium" installed.
  3. If its in the folder of python version that you are not using, just copy the folders in the correct python version folder in "Lib\site-packages" path.

This should do it....

Jabir
  • 61
  • 7
1

You're might run a virtual environment and installed selenium in your default python environment. If so try to install it into the local one.

Huhngut
  • 402
  • 6
  • 13
0

If you already installed Selenium by pip install selenium or by any other way and still see that error I guess you are missing a system PATH set to Python or Selenium folder in your machine.
So just add those folders locations to you machine PATH as described here or any other place.

Prophet
  • 32,350
  • 22
  • 54
  • 79