I’m trying to write a script to check a website. It’s the first time I’m using selenium. I’m trying to run the script on a OSX system. Although I checked in /Library/Python/2.7/site-packages and selenium-2.46.0-py2.7.egg is present, when I run the script it keeps telling me that there is no selenium module to import.

This is the log that I get when I run my code:

Traceback (most recent call last):
  File "/Users/GiulioColleluori/Desktop/Class_Checker.py", line 10, in <module>
    from selenium import webdriver
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

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 it’s clear to me that you’ve already did that, but you still get the ImportError: No module named 'selenium'.

So, what’s 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 you’re probably running a version of Python, in which you didn’t install Selenium. For instance: /Library/Python/3.8/site-packages… you won’t find Selenium installed here and that’s why the module isn’t found.

The solution?
You have to install selenium in the same directory to the Python version you’re 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)
enter image description here

Ready! Now your Python interpreter should find the module.

It’s 2020 now, use python3 consistently

  • pip3 install selenium
  • python3 xxx.py

I meet the same problem when I install selenium using pip3, but run scripts using python.

If you are using Anaconda or Spyder in windows, install selenium by this code in cmd:

conda install selenium

If you are using Pycharm IDE in windows, install selenium by this code in cmd:

pip install selenium

I had the same problem. Using sudo python3 -m pip install selenium may work.

Your IDE might be pointing to a different installation of Python than where Selenium is installed.

I’m using Eclipse and when I ran ‘quick auto-configure’ under:

Preferences > PyDev > Interpreters > Python Interpreter

it pointed to a different version of Python than where pip or easy_install actually installed it.

Selenium worked from the Terminal so I determined which version of python my Terminal was using by running this:

python -c "import sys; print(sys.path)"

then had Eclipse point to that same location, which for me on my 10.11 Mac was here:


You can run “Advanced Auto-Config” as well to see all of the installed versions of python and select the one you want to use. When I selected that same location using “Advanced Auto-Config” it finally showed me the Selenium folder as it went through the configuration steps.

If pip isn’t already installed, then first try to bootstrap it from the standard library:

sudo python -m ensurepip --default-pip

Ensure pip, setuptools, and wheel are up to date

sudo python -m pip install --upgrade pip setuptools wheel

Now Install Selenium

sudo pip install selenium

Now run your runner.

Hope this helps. Happy Coding !!

Even though the egg file may be present, that does not necessarily mean that it is installed. Check out this previous answer for some hint:

How to install Selenium WebDriver on Mac OS

I ran into the same problem with pycharm where my modules wouldn’t import after installing them on ubuntu with pip.

If you go File-> Settings -> Project > Python Interpreter

You can click the ‘+’ on the right hand side and import modules into the interpreter.

Not sure if that’s your issue but hope this helps.

I had a similar problem.
It turned out that I had an alias defined for python like so:

alias python=/usr/bin/python3

Apparently virtualenv does not check or update your aliases.

So the solution for me was to remove the alias:

unalias python

Now when I run python, I get the one from the virtual environment.
Problem solved.

make easy install again by downloading selenium webdriver from its website it is not installed properly.

Edit 1:
extract the .tar.gz folder go inside the directory and run python setup.py install from terminal.make sure you have installed setuptools.

Navigate to your scripts folder in Python directory (C:\Python27\Scripts) and open command line there (Hold shift and right click then select open command window here). Run pip install -U selenium

If you don’t have pip installed, go ahead and install pip first

pip3 install selenium

Try this if you have python3.

install urllib3

!pip3 install urllib3

import urllib3

than install it

!pip3 install selenium

import selenium

first you should be sure that selenium is installed in your system.

then install pycharm https://itsfoss.com/install-pycharm-ubuntu/

now if an of packages are not installed it will show red underlines. click on it and install from pycharm.

like for this case click on selenium option in import statement, there you would getting some options. click on install selenium. it will install and automatically run the code successfully if all your drivers are placed in proper directories.


pip install selenium


sudo pip install selenium

While pip install might work. Please check the project structure and see if there is no virtual environment already (It is a good practice to have one) created in the project. If there is, activate it with source <name_of_virtual_env>/bin/activate (for MacOS) and venv\Scripts\Activate.ps1 (for Windows powershell) or venv\Scripts\activate.bat (for Windows cmd). then pip install selenium into the environment.

If it isn’t,
check if you have a virtual environment with virtualenv --version
If it displays an error, install it with pip install virtualenv
then create a virtual environment with
virtualenv <name_of_virtual_env> (Both Windows and MacOS)or

python -m venv <name_of_virtual_env> (Windows Only)

then activate the virtual environment
source <name_of_virtual_env>/bin/activate (for MacOS) and
venv\Scripts\Activate.ps1 (for Windows powershell) or
venv\Scripts\activate.bat (for Windows cmd).
then install selenium with pip install -U selenium (it will install the latest version).
If it doesn’t display an error, just create a virtual environment in the project, activate it and install selenium inside of it.

I was having the same issue when using python 3 with conda distribution, trying to run code on Jupyter in a custom virtualenv.
I tried manually installing, installing with pip3, conda etc in anaconda prompt repeatedly but continued to get the import error.
Finally solved it by installing it in the Jupyter Tab itself.
in Jupyter, in a line, run conda install selenium
That’s it
(If you’re facing a similar env that is)