python – ImportError: No module named selenium

python – ImportError: No module named selenium

If you have pip installed you can install selenium like so.

pip install selenium

or depending on your permissions:

sudo pip install selenium

For python3:

sudo pip3 install selenium

As you can see from this question pip vs easy_install pip is a more reliable package installer as it was built to improve easy_install.

I would also suggest that when creating new projects you do so in virtual environments, even a simple selenium project. You can read more about virtual environments here. In fact pip is included out of the box with virtualenv!

For python3, on a Mac you must use pip3 to install selenium.

sudo pip3 install selenium

python – ImportError: No module named selenium

I had the exact same problem and it was driving me crazy (Windows 10 and VS Code 1.49.1)

Other answers talk about installing Selenium, but its clear to me that youve already did that, but you still get the ImportError: No module named selenium.

So, whats going on?

Two things:

  1. You installed Selenium in this folder /Library/Python/2.7/site-packages and selenium-2.46.0-py2.7.egg
  2. But youre probably running a version of Python, in which you didnt install Selenium. For instance: /Library/Python/3.8/site-packages… you wont find Selenium installed here and thats why the module isnt found.

The solution?
You have to install selenium in the same directory to the Python version youre using or change the interpreter to match the directory where Selenium is installed.

In VS Code you change the interpreter here (at the bottom left corner of the screen)

Ready! Now your Python interpreter should find the module.

Leave a Reply

Your email address will not be published.