Fix the Modulenotfounderror no module named selenium in Python

Solve the no module named selenium exception

You will receive the module not found exception for the selenium library, when trying to invoke selenium without first installing it in your Python dev environment. Use the Python package installing utility (pip) or conda (if you are on Anaconda – to solve this issue:

pip install selenium

# alternatively

conda install selenium

Understanding the error message

When you invoke selenium from your Python development environment (such as Jupyter, VS Code, PyCharm, Spyder or others), without first installing it, you will receive the following error message:

The reason is that selenium is a 3rd party library, that has to be explicitly be installed in your Python environment before being used.

Fixing the no module found error for selenium

Luckily troubleshooting this error is most often than not, quite simple.

Users of standalone envs or virtualenv:

  • Save your Python script.
  • Close your Python dev editor of choice.
  • Invoke command prompt or Terminal.
  • Navigate to your Python directory (location of your python.exe file). Windows users – No need to execute this step if you have added Python to your PATH environment variable.
  • Call pip and install selenium:
pip install selenium
  • Once done, reopen your dev environment and import selenium into your script.

Users of Anaconda and MiniConda

  • Invoke the Terminal (macos or Linux) or the Anaconda Prompt in Windows (by hitting the Windows button and simply typing Anaconda.
  • Activate your conda environment.
  • Then type:
conda install selenium
  • Package metadata and contents will be collected then installation will execute. Once done, close the Anaconda prompt or Terminal and resume your coding.

Troubleshooting

[Errno 13] Permission denied – if encountering permission errors, make sure to run the command prompt in administrative mode (Right click the prompt icon and then select Run in Administrator mode).

Follow up learning

Fixing the no module found exception in PyCharm and Jupyter Notebooks