No module named selenium ошибка

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's user avatar

Dharman

30.4k22 gold badges84 silver badges132 bronze badges

asked Jun 30, 2015 at 20:13

Giulio Colleluori's user avatar

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

gffbss's user avatar

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:

  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.

answered Oct 3, 2020 at 15:08

Guzman Ojero's user avatar

Guzman OjeroGuzman Ojero

2,6621 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

Brian's user avatar

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's user avatar

Samsul Islam

2,5682 gold badges17 silver badges23 bronze badges

answered Mar 19, 2020 at 8:11

Lebecca's user avatar

LebeccaLebecca

2,35114 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 Baziyad's user avatar

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's user avatar

Samsul Islam

2,5682 gold badges17 silver badges23 bronze badges

answered Aug 31, 2019 at 16:40

tachish's user avatar

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

mindmischief's user avatar

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 Siddiqui's user avatar

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

Ehgriez's user avatar

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

Community's user avatar

answered Jun 30, 2015 at 20:35

Steven Correia's user avatar

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's user avatar

Samsul Islam

2,5682 gold badges17 silver badges23 bronze badges

answered Aug 18, 2019 at 15:27

nahurmf's user avatar

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

as1992's user avatar

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

Rashid's user avatar

0

pip3 install selenium

Try this if you have python3.

answered Dec 29, 2018 at 21:42

Wimukthi Rajapaksha's user avatar

install urllib3

!pip3 install urllib3

import urllib3

than install it

!pip3 install selenium

import selenium

answered Apr 26, 2020 at 18:24

Sara Bouraya's user avatar

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 sai's user avatar

Rohit saiRohit sai

1191 silver badge10 bronze badges

Windows:

pip install selenium

Unix:

sudo pip install selenium

Paul Roub's user avatar

Paul Roub

36.3k27 gold badges83 silver badges93 bronze badges

answered Aug 17, 2019 at 19:48

Gunjan Paul's user avatar

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_m_sanguine's user avatar

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

Kriticoder's user avatar

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

MacDonald Ejime  Oghenefejiro's user avatar

Error:

ModuleNotFoundError: No module named ‘selenium’

Solutions:

pip

pip install selenium

pip3

pip3 install selenium

answered Aug 31, 2022 at 7:26

Shehan Jayalath's user avatar

If the previous answers don’t solve your problem, try this (in Linux)

  1. Delete the venv file
  2. Close the terminal (or come out of the current venv)
  3. Install seleinum now (pip install selenium or pip3 install selenium)
  4. Now activate the venv

Eric Aya's user avatar

Eric Aya

69.4k35 gold badges181 silver badges252 bronze badges

answered Mar 31 at 5:16

Sathyanarayanan Dhanushkodi's user avatar

Установлен последний питон, selenium, pip.
Через Pycharm пытаюсь запустить элементарный тест

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome(‘C:\Python\123\chromedriver.exe’)
driver.get(«www.google.com»)

На что выдаётся ответ
«C:PythonvenvScriptspython.exe C:/Python/123/123.py
Traceback (most recent call last):
File «C:/Python/123/123.py», line 2, in
from selenium.webdriver.common.keys import Keys
ModuleNotFoundError: No module named ‘selenium.webdriver.common’

Process finished with exit code 1″

В IDLE всё выполняется правильно.

Если убрать вторую строку, получаем
«AttributeError: module ‘selenium.webdriver’ has no attribute ‘Chrome'»

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

Modulenotfounderror no module named selenium

Modulenotfounderror no module named 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

no module named selenium using conda

no module named selenium using conda

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.

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

Lopez

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

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:

  1. 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.
  2. You might have selenium installed in a virtual environment, and you are not activating the virtual environment before running your code.
  3. 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:

  1. Install selenium with pip using /usr/bin/ Python version
  2. Install Python using Homebrew, now you have Python in /opt/homebrew/
  3. 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:

  1. Turn off the virtual environment so that pip installs to your computer
  2. Install the selenium in the virtual environment with pip

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:

  1. Open the command palette (CTRL + Shift + P for Windows and ⌘ + Shift + P for Mac)
  2. 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.

Понравилась статья? Поделить с друзьями:
  • No module named pyside2 ошибка
  • No module named colorama ошибка
  • Nissan tiida ошибка подушки безопасности
  • Nissan tiida ошибка p1611
  • Nissan tiida ошибка p1126