Ajinkya
Ajinkya

Reputation: 1867

No module named selenium even after Requirement already satisfied: selenium

I have this strange error:

aj@vds725:~/web_scraping$ python
Python 3.6.7 (default, Oct 25 2018, 09:16:13) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import selenium
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/aj/web_scraping/selenium.py", line 2, in <module>
    from selenium.webdriver.common.action_chains import ActionChains
ModuleNotFoundError: No module named 'selenium.webdriver'; 'selenium' is not a package

But I already have installed selenium

aj@vds725:~/web_scraping$ pip install selenium
Requirement already satisfied: selenium in /usr/local/lib/python3.6/dist-packages (3.141.0)
Requirement already satisfied: urllib3 in /usr/local/lib/python3.6/dist-packages (from selenium) (1.24.3)

Is there a possible workaround around this also why is this happening?

Upvotes: 0

Views: 1596

Answers (1)

tryexceptcontinue
tryexceptcontinue

Reputation: 1877

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/aj/web_scraping/selenium.py", line 2, in <module>

The problem is that you have named your module selenium.py, so when you try to import selenium it is targeting your module instead of the selenium package installed with your python version.

It is a good practice to avoid naming your modules after other modules / packages for this very reason. Rename /home/aj/web_scraping/selenium.py to /home/aj/web_scraping/a_name_not_used_by_python.py

Upvotes: 1

Related Questions