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'
Dharman♦
30.5k22 gold badges85 silver badges133 bronze badges
asked Jun 30, 2015 at 20:13
0
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!
answered Jun 30, 2015 at 21:46
2
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:
- You installed Selenium in this folder /Library/Python/2.7/site-packages and selenium-2.46.0-py2.7.egg
- 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)
Ready! Now your Python interpreter should find the module.
answered Oct 3, 2020 at 15:08
Guzman OjeroGuzman Ojero
2,7121 gold badge19 silver badges20 bronze badges
1
For python3, on a Mac you must use pip3 to install selenium.
sudo pip3 install selenium
answered May 18, 2018 at 0:01
BrianBrian
4886 silver badges11 bronze badges
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
.
Samsul Islam
2,5682 gold badges17 silver badges23 bronze badges
answered Mar 19, 2020 at 8:11
LebeccaLebecca
2,36114 silver badges32 bronze badges
1
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
answered Jan 10, 2019 at 20:00
Hamed BaziyadHamed Baziyad
1,9445 gold badges26 silver badges40 bronze badges
I had the same problem. Using sudo python3 -m pip install selenium
may work.
Samsul Islam
2,5682 gold badges17 silver badges23 bronze badges
answered Aug 31, 2019 at 16:40
tachishtachish
711 silver badge1 bronze badge
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:
/Library/Frameworks/Python.framework/Versions/Current/bin/python2.7/
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.
answered Jun 16, 2017 at 23:27
1
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 !!
answered Dec 4, 2019 at 10:32
Saif SiddiquiSaif Siddiqui
8361 gold badge13 silver badges33 bronze badges
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.
answered Aug 10, 2020 at 10:06
2
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
answered Jun 30, 2015 at 20:35
2
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.
Samsul Islam
2,5682 gold badges17 silver badges23 bronze badges
answered Aug 18, 2019 at 15:27
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.
answered Jun 30, 2015 at 20:47
as1992as1992
531 silver badge8 bronze badges
2
Navigate to your scripts folder in Python directory (C:Python27Scripts) 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
answered Aug 1, 2017 at 6:32
0
pip3 install selenium
Try this if you have python3.
answered Dec 29, 2018 at 21:42
install urllib3
!pip3 install urllib3
import urllib3
than install it
!pip3 install selenium
import selenium
answered Apr 26, 2020 at 18:24
1
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.
answered May 15, 2017 at 6:51
Rohit saiRohit sai
1191 silver badge10 bronze badges
Windows:
pip install selenium
Unix:
sudo pip install selenium
Paul Roub
36.3k27 gold badges83 silver badges93 bronze badges
answered Aug 17, 2019 at 19:48
Gunjan PaulGunjan Paul
5136 silver badges12 bronze badges
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 venvScriptsActivate.ps1
(for Windows powershell) or venvScriptsactivate.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
with
source <name_of_virtual_env>/bin/activate
(for MacOS) and
venvScriptsActivate.ps1
(for Windows powershell) or
venvScriptsactivate.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.
answered Oct 2, 2020 at 11:49
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)
answered Jun 23, 2021 at 2:27
KriticoderKriticoder
931 silver badge6 bronze badges
I had same issue and tried all that are mentioned above but none work for me until I saw py -m pip install -U selenium
answered Jun 19, 2022 at 14:04
Error:
ModuleNotFoundError: No module named ‘selenium’
Solutions:
pip
pip install selenium
pip3
pip3 install selenium
answered Aug 31, 2022 at 7:26
If the previous answers don’t solve your problem, try this (in Linux)
- Delete the venv file
- Close the terminal (or come out of the current venv)
- Install seleinum now (pip install selenium or pip3 install selenium)
- Now activate the venv
Eric Aya
69.5k35 gold badges181 silver badges252 bronze badges
answered Mar 31 at 5:16
When using Selenium with Python, you may receive an error message that says ModuleNotFoundError: No module named ‘selenium’ in Python. This is quite frustrating. This article will show you how to fix this error and get back to writing your Selenium scripts.
What is Selenium in Python?
Selenium is one of the most powerful open-source testing tools for Web application testing available today. Most browsers, including Internet Explorer, Mozilla Firefox, Chrome, Safari, and Opera, and most operating systems, including Windows, Mac, and Linux, can run the Selenium script.
The Selenium module is not installed
This error can occur if you attempt to run a Selenium test in Python without the selenium module installed. Examine the code below to understand the error better.
# Import but not install the Selenium module from selenium import webdriver # Try using Selenium to get the title of LearnShareIT PATH = 'C:Program Files (x86)chromedriver.exe' drv = webdriver.Chrome(PATH) drv.get('https://learnshareit.com/') print(drv.title) drv.quit()
Error:
ModuleNotFoundError: No module named 'selenium'
We can fix this error by installing the Selenium module. This can be done with the package installer for Python(pip).
Pip is a Python package manager that allows you to install and manage Python packages such as Selenium. Simply type the following into your terminal to install Selenium using pip:
pip install selenium
Use the following command line if you’re using Python 3 on Linux or macOS:
pip3 install selenium
Or, if you’re using Anaconda, use the following command line:
conda install -c conda-forge selenium
These commands will download and install the latest version of Selenium.
If you see a message starting with “Successfully installed”. That means you’ve installed Selenium successfully. You can now use Selenium with Python without getting this error.
# Installed Selenium module from selenium import webdriver # Try using Selenium to get the title of LearnShareIT PATH = 'C:Program Files (x86)chromedriver.exe' drv = webdriver.Chrome(PATH) drv.get('https://learnshareit.com/') print(drv.title) drv.quit()
Output:
LearnShareIT - Let's learn and share knowledge about IT
Using the wrong name when importing
If you import the name ‘Selenium’ into the program, Python will throw an error like the sample code below.
# Import with the name 'Selenium' from Selenium import webdriver
Error:
ModuleNotFoundError: No module named 'Selenium'
This is a common spelling error made by Python beginners who are unfamiliar with modules. We must avoid using names that contain uppercase letters when importing the Selenium module. To fix the error in this case, lowercase all characters when importing. Like this:
# Import with the lowercase name 'selenium' from selenium import webdriver # Try using Selenium to get the title of LearnShareIT PATH = 'C:Program Files (x86)chromedriver.exe' drv = webdriver.Chrome(PATH) drv.get('https://learnshareit.com/') print(drv.title) drv.quit()
Output:
LearnShareIT - Let's learn and share knowledge about IT
Summary
We have clarified some causes and solutions for the ModuleNotFoundError: No module named ‘selenium’ above. The main cause of this error is that the Selenium module has not been installed. Therefore, if you encounter this or a similar error in the future, make sure you have all of the required modules installed.
Happy coding!
Maybe you are interested:
- No module named ‘flask_sqlalchemy’ in Python
- ModuleNotFoundError: No module named ‘OpenSSL’ in Python
- No module named ‘flask_restful’ in Python
Hi, I’m Cora Lopez. I have a passion for teaching programming languages such as Python, Java, Php, Javascript … I’m creating the free python course online. I hope this helps you in your learning journey.
Name of the university: HCMUE
Major: IT
Programming Languages: HTML/CSS/Javascript, PHP/sql/laravel, Python, Java
ModuleNotFoundError: No module named selenium error occurs if the selenium module is not properly installed or not configured properly. Selenium library provides features to automate the browser which has multiple use cases like automation testing, backend to virtual assistant, etc. Selenium comes with multi-programming language support like Java, Python, etc. In this article, we will specifically focus on solving the error No module named selenium with Python Interpreter.
The best solution is to install or reinstall selenium package to fix this error. But how?
Solution 1: Use pip to install selenium –
Use the below command to use pip for selenium installation.
pip install selenium
Optional Scenario :
1.1. In case the system needs admin privileges to run the above pip command for selenium installation. Then add sudo keyword at the beginning of the command for the Linux family OS. If you are using a Window-based OS, open the command prompt and run the above command only.
sudo pip install selenium
1.2 If you need to install any specific version for selenium all we need to mention in the same command.
pip install selenium==4.5.0
Regarding different versions of selenium with pip, refer selenium release notes on PyPI.
1.3 In case pip is outdated or failing then use the below command as a prerequisite before you run any of the above commands.
python -m ensurepip --default-pip
python -m pip install --upgrade pip setuptools wheel
pip install selenium
1.4 if the path is not set for pip itself then run the below command.
python -m pip install selenium
Solution 2: Use conda to install selenium –
Similar to pip we can use conda to install selenium with the below command.
conda install -c conda-forge selenium
Solution 3: Use source code to install selenium –
Installation for scratch. For this we need the download the source code. Since this source code is generic and has an implementation for multiple programming languages like java, python. Hence we need to first navigate into the Py folder and then build the wheel or any other binding format.
Thanks
DSL Team
Join our list
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
We respect your privacy and take protecting it seriously
Thank you for signup. A Confirmation Email has been sent to your Email Address.
Something went wrong.
A common error you may encounter when using Python is modulenotfounderror: no module named ‘selenium’.
This error occurs when the Python interpreter cannot detect the Selenium library in your current environment.
This tutorial goes through the exact steps to troubleshoot this error for the Windows, Mac and Linux operating systems.
Table of contents
- ModuleNotFoundError: no module named ‘selenium’
- What is Selenium?
- How to Install Selenium on Windows Operating System
- Selenium installation on Windows Using pip
- How to Install Selenium on Mac Operating System using pip
- How to Install Selenium on Linux Operating Systems
- Installing pip for Ubuntu, Debian, and Linux Mint
- Installing pip for CentOS 8 (and newer), Fedora, and Red Hat
- Installing pip for CentOS 6 and 7, and older versions of Red Hat
- Installing pip for Arch Linux and Manjaro
- Installing pip for OpenSUSE
- Selenium installation on Linux with Pip
- Installing Selenium Using Anaconda
- Check Selenium Version
- Summary
ModuleNotFoundError: no module named ‘selenium’
What is Selenium?
Selenium is a suite of tools for automating web browsers. You can use Selenium to automate web applications for testing purposes, though it is not only for testing.
The simplest way to install Selenium is to use the package manager for Python called pip. The following installation instructions are for the major Python version 3.
How to Install Selenium on Windows Operating System
First, you need to download and install Python on your PC. Ensure you select the install launcher for all users and Add Python to PATH checkboxes. The latter ensures the interpreter is in the execution path. Pip is automatically on Windows for Python versions 2.7.9+ and 3.4+.
You can check your Python version with the following command:
python3 --version
You can install pip on Windows by downloading the installation package, opening the command line and launching the installer. You can install pip via the CMD prompt by running the following command.
python get-pip.py
You may need to run the command prompt as administrator. Check whether the installation has been successful by typing.
pip --version
Selenium installation on Windows Using pip
To install Selenium, run the following command from the command prompt.
pip3 install selenium
How to Install Selenium on Mac Operating System using pip
Open a terminal by pressing command (⌘) + Space Bar to open the Spotlight search. Type in terminal and press enter. To get pip, first ensure you have installed Python3:
python3 --version
Python 3.8.8
Download pip by running the following curl command:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
The curl command allows you to specify a direct download link. Using the -o option sets the name of the downloaded file.
Install pip by running:
python3 get-pip.py
From the terminal, use pip3 to install Selenium:
pip3 install selenium
How to Install Selenium on Linux Operating Systems
All major Linux distributions have Python installed by default. However, you will need to install pip. You can install pip from the terminal, but the installation instructions depend on the Linux distribution you are using. You will need root privileges to install pip. Open a terminal and use the commands relevant to your Linux distribution to install pip.
Installing pip for Ubuntu, Debian, and Linux Mint
sudo apt install python-pip3
Installing pip for CentOS 8 (and newer), Fedora, and Red Hat
sudo dnf install python-pip3
Installing pip for CentOS 6 and 7, and older versions of Red Hat
sudo yum install epel-release
sudo yum install python-pip3
Installing pip for Arch Linux and Manjaro
sudo pacman -S python-pip
Installing pip for OpenSUSE
sudo zypper python3-pip
Selenium installation on Linux with Pip
Once you have installed pip, you can install Selenium using:
pip3 install selenium
Installing Selenium Using Anaconda
First, to create a conda environment to install PIL.
conda create -n selenium python=3.6
Then activate the selenium container. You will see “selenium” in parentheses next to the command line prompt.
source activate selenium
Now you’re ready to install Selenium using conda.
Anaconda is a distribution of Python and R for scientific computing and data science. You can install Anaconda by going to the installation instructions. Once you have installed Anaconda and created your conda environment, you can install Selenium using one of the following commands:
conda install -c conda-forge selenium
Check Selenium Version
Once you have successfully installed Selenium, you can check the version of Selenium. If you used pip to install Selenium, you can use pip show from your terminal.
pip show selenium
Name: selenium
Version: 4.1.0
Second, within your python program, you can import selenium and then reference the __version__ attribute:
import selenium
print(selenium.__version__)
4.1.0
If you used conda to install Selenium, you could check the version using the following command:
conda list -f selenium
# Name Version Build Channel
selenium 3.141.0 py36hfa26744_1002 conda-forge
Summary
Congratulations on reading to the end of this tutorial. The modulenotfounderror occurs if you misspell the module name, incorrectly point to the module path or do not have the module installed in your Python environment. If you do not have the module installed in your Python environment, you can use pip to install the package. However, you must ensure you have pip installed on your system. You can also install Anaconda on your system and use the conda install command to install Selenium.
Go to the online courses page on Python to learn more about Python for data science and machine learning.
For further reading on missing modules in Python, go to the article: How to Solve Python ModuleNotFoundError: no module named ‘urllib2’.
Have fun and happy researching!
Python shows no module named selenium
error when it can’t find the selenium
library you imported in your code.
This can mean that you don’t have selenium installed, or you installed it for a different version of Python (if you have multiple Python versions)
This article shows simple steps you can do to fix this error.
Why no module named selenium error occurs
This error occurs when you try to import the selenium
library in your code like this:
import selenium
#or
from selenium import webdriver
When Python can’t find the library, it raises the following error:
Traceback (most recent call last):
File ...
import selenium
ModuleNotFoundError: No module named 'selenium'
Because selenium
isn’t a standard Python library, you need to install it using pip
before you can import it.
Here’s the command to install selenium with pip:
pip install selenium
# or if you have Python 3
pip3 install selenium
Once you have selenium
library installed, you should be able to run the code without any errors.
If that doesn’t work, then you may have installed multiple versions of Python on your computer.
One of the following scenarios may happen in your case:
- You have multiple versions of Python installed on your system, and you are using a different version of Python than the one where
selenium
is installed. - You might have
selenium
installed in a virtual environment, and you are not activating the virtual environment before running your code. - Your IDE uses a different version of Python from the one that has
selenium
installed
Let’s see how to fix these errors.
Case#1 — You have multiple versions of Python
If you have multiple versions of Python installed on your system, you need to make sure that you are using the specific version where the selenium
package is installed.
You can test this by running the which -a python
or which -a python3
command from the terminal:
$ which -a python
/opt/homebrew/bin/python
/usr/bin/python
In the example above, there are two versions of Python installed on /opt/homebrew/bin/python
and /usr/bin/python
.
Suppose you run the following steps in your project:
- Install
selenium
withpip
using/usr/bin/
Python version - Install Python using Homebrew, now you have Python in
/opt/homebrew/
- Then add
import selenium
in your code
The steps above will cause the error because selenium
is installed in /usr/bin/
, and your code is probably executed using Python from /opt/homebrew/
path.
To solve this error, you need to run pip install selenium
command again so that the package is installed and accessible by the new Python version.
Finally, keep in mind that you can also have pip
and pip3
available on your computer.
These days, the pip
command is used to install modules for Python 2, while pip3
installs for Python 3. Make sure that you are using the right command for your situation.
Next, you can also have the package installed in a virtual environment.
Case#2 — You are using Python virtual environment
Python venv
package allows you to create a virtual environment where you can install different versions of packages required by your project.
If you are installing selenium
inside a virtual environment, then the module won’t be accessible outside of that environment.
Even when you never run the venv
package, Python IDE like Anaconda and PyCharm usually create their own virtual environment when you create a Python project with them.
You can see if a virtual environment is activated or not by looking at your command prompt.
When a virtual environment is activated, the name of that environment will be shown inside parentheses as shown below:
In the picture above, the name of the virtual environment (base)
appears when the Conda virtual environment is activated.
To solve this, you can either:
- Turn off the virtual environment so that
pip
installs to your computer - Install the
selenium
in the virtual environment withpip
You can choose the solution that works for your project.
When your virtual environment is created by Conda, run the conda deactivate
command. Otherwise, running the deactivate
command should work.
To activate your virtual environment, use one of the following commands:
# For Conda:
conda activate <env_name>
# For venv:
source <env_name>/bin/activate
For Pycharm, you need to follow the Pycharm guide to virtual environment.
Case#3 — IDE using a different Python version
Finally, the IDE from where you run your Python code may use a different Python version when you have multiple versions installed.
If you use VSCode, run the steps below to check available Python interpreters:
- Open the command palette (
CTRL + Shift + P
for Windows and⌘ + Shift + P
for Mac) - Run the
Python: Select Interpreter
command.
You should see all available Python versions listed as follows:
You need to use the same version where you installed selenium
so that the module can be found when you run the code from VSCode.
If you use Pycharm, follow the Pycharm configuring Python interpreter guide.
Once done, the import selenium
statement shouldn’t cause any error.
Conclusion
To conclude, the ModuleNotFoundError: No module named 'selenium'
error occurs when the selenium
package is not available in your Python environment.
To fix this error, you need to install selenium
using pip
.
If you already have the module installed, make sure you are using the correct version of Python, activate the virtual environment if you have one, and check for the Python version used by your IDE.
By following these steps, you should be able to import selenium
modules without any error.