Меню

Ошибка modulenotfounderror no module named selenium

I get an error while running this selenium script. Please suggest what can be done to fix this:
Script:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import re
import csv
import time
driver = webdriver.chrome("<webdriver path>")

driver.get("https://www.google.com/")
driver.find_element_by_xpath('//*[@title="Search"]')
send_keys('abc')
driver.find_element_by_xpath('//*[@class="sbico _wtf _Qtf"]').click()
time.sleep(5)
driver.find_element_by_xpath('//[@id="rso"]/div[1]/div/div[1]/div/div/h3/a')
print(var)

Error:

Traceback (most recent call last):
File «C:/Users/admin/Desktop/test2.py», line 2, in
from selenium import webdriver
ModuleNotFoundError: No module named ‘selenium’

I have installed Python 3.6 on win 7 Professional 32 bit. I have Selenium Standalone Server version 3.4.0(link)

frianH's user avatar

frianH

7,1756 gold badges19 silver badges43 bronze badges

asked May 5, 2017 at 5:43

Google User's user avatar

4

Try installing selenium using pip. Use the following command.

python -m pip install -U selenium

answered May 5, 2017 at 5:57

shahin's user avatar

shahinshahin

3,4471 gold badge16 silver badges17 bronze badges

3

Seems like you have not run the installation command for webdriver_manager.

Use the following command:

pip install webdriver_manager

But before this, make sure you have properly installed selenium as well. If not, use the following command to install selenium:

pip install selenium

answered Jan 15, 2020 at 19:51

NAVNEET CHANDAN's user avatar

Remarks to virtual environments

virtualenv

If you are using a virtual environment like virtualenv.
You have to make sure that the module selenium is installed
1.) in the virtual environment and
2.) in the default settings (when the virtual environment is deactivated).

Otherwise you will get the error message:
ModuleNotFoundError: No module named ‘selenium’

Example

Install selenium in the default settings: pip install selenium

Create virtual environment (on windows): py -m virtualenv folder_env

Activate virtual environment (on windows): source folder_env/Scripts/activate

Check virtual environment settings: which python and which pip

Install selenium: pip install selenium

Check pip list for selenium: pip list

(Optional) Exit virtual environment: deactivate folder_env

Miscellaneous

Virtualenv by Corey Schafer: https://www.youtube.com/watch?v=N5vscPTWKOk
virtualenv is not a native module, you have to install it with
pip install virtualenv

answered Mar 3, 2019 at 7:29

Dataku's user avatar

DatakuDataku

5796 silver badges9 bronze badges

driver = webdriver.chrome(«»)

there is no such class ^^. It is named webdriver.Chrome()

answered Mar 20, 2018 at 14:54

Corey Goldberg's user avatar

Corey GoldbergCorey Goldberg

57.8k28 gold badges123 silver badges141 bronze badges

Okay, the Quick and Easy Solution is to Go to Your Python Version Location, Then Libs, and then Site-packages.

ex —
C:UsersAdminAppDataLocalProgramsPythonPython38Libsite-packages

Try Deleting and Reinstalling Selenium, and Try Running the Code.

answered Apr 22, 2020 at 18:12

singopedia shaad's user avatar

  1. You can enter these commands «pip install webdriver_manager»
  2. Then «pip install selenium»

answered Jun 24, 2020 at 14:49

Ankit Rai's user avatar

Ankit RaiAnkit Rai

2393 silver badges3 bronze badges

If Webdriver Manager is not installed, open CMD -> Type «pip install webdriver_manager» and enter.

If you found such an issue, then in Pycharm specific application:

  1. Find path where your Python library exists. (Like C:UserscpAppDataLocalProgramsPythonPython38-32Libsite-packages)
  2. Copy site-packages folder.
  3. Go to Project.
  4. Find «Lib» folder.
  5. Expand Lib folder and you will find site_packages over there.
  6. Paste site-packages.

I believe it will help you out.

answered Aug 8, 2020 at 12:19

Rounak Dubey's user avatar

1

Late answer but it is worth mentioning.

Working on VSCode under Windows and I had this issue ModuleNotFoundError: No module named 'selenium', none of the solutions worked for me.

Finally, I figured out that Python was installed twice:

  • From the Windows store which will reside under : C:Users<user>AppDataLocalMicrosoftPython

  • Normal Install (i.e. download and install in a chosen directory, mine was C:Users<user>AppDataLocalProgramsPython)

What drove me crazy was when I open the terminal and run :

pip list

I found the selenium there, and it keeps telling me on the other hand : No module named 'selenium'

And it appears that VsCode launcher (button to execute my .py file) was bound, somehow, to the former location (the one downloaded from the store) while its terminal was linked to the latter one, so I uninstall it (the one from Windows Store) and selected the proper location of Python in the launcher’s config in VsCode and it worked.

answered Jan 25, 2022 at 13:22

SeleM's user avatar

SeleMSeleM

9,0625 gold badges31 silver badges50 bronze badges

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!

Quick Fix: Python raises the ImportError: No module named 'selenium' when it cannot find the library selenium. The most frequent source of this error is that you haven’t installed selenium explicitly with pip install selenium. Alternatively, you may have different Python versions on your computer, and selenium is not installed for the particular version you’re using.

Problem Formulation

You’ve just learned about the awesome capabilities of the selenium library and you want to try it out, so you start your code with the following statement:

import selenium

This is supposed to import the selenium library into your (virtual) environment. However, it only throws the following ImportError: No module named selenium:

>>> import selenium
Traceback (most recent call last):
  File "<pyshell#6>", line 1, in <module>
    import selenium
ModuleNotFoundError: No module named 'selenium'

Solution Idea 1: Install Library selenium

The most likely reason is that Python doesn’t provide selenium in its standard library. You need to install it first!

Before being able to import the selenium module, you need to install it using Python’s package manager pip. Make sure pip is installed on your machine.

To fix this error, you can run the following command in your Windows shell:

$ pip install selenium

This simple command installs selenium in your virtual environment on Windows, Linux, and MacOS. It assumes that your pip version is updated. If it isn’t, use the following two commands in your terminal, command line, or shell (there’s no harm in doing it anyways):

$ python -m pip install --upgrade pip
$ pip install selenium

💡 Note: Don’t copy and paste the $ symbol. This is just to illustrate that you run it in your shell/terminal/command line.

Solution Idea 2: Fix the Path

The error might persist even after you have installed the selenium library. This likely happens because pip is installed but doesn’t reside in the path you can use. Although pip may be installed on your system the script is unable to locate it. Therefore, it is unable to install the library using pip in the correct path.

To fix the problem with the path in Windows follow the steps given next.

Step 1: Open the folder where you installed Python by opening the command prompt and typing where python

Step 2: Once you have opened the Python folder, browse and open the Scripts folder and copy its location. Also verify that the folder contains the pip file.

Step 3: Now open the Scripts directory in the command prompt using the cd command and the location that you copied previously.

Step 4: Now install the library using pip install selenium command. Here’s an analogous example:

After having followed the above steps, execute our script once again. And you should get the desired output.

🌍 Recommended Tutorial: How to Install Selenium on PyCharm?

Other Solution Ideas

  • The ModuleNotFoundError may appear due to relative imports. You can learn everything about relative imports and how to create your own module in this article.
  • You may have mixed up Python and pip versions on your machine. In this case, to install selenium for Python 3, you may want to try python3 -m pip install selenium or even pip3 install selenium instead of pip install selenium
  • If you face this issue server-side, you may want to try the command pip install --user selenium
  • If you’re using Ubuntu, you may want to try this command: sudo apt install selenium
  • You can check out our in-depth guide on installing selenium here.
  • You can also check out this article to learn more about possible problems that may lead to an error when importing a library.

Understanding the “import” Statement

import selenium

In Python, the import statement serves two main purposes:

  • Search the module by its name, load it, and initialize it.
  • Define a name in the local namespace within the scope of the import statement. This local name is then used to reference the accessed module throughout the code.

What’s the Difference Between ImportError and ModuleNotFoundError?

What’s the difference between ImportError and ModuleNotFoundError?

Python defines an error hierarchy, so some error classes inherit from other error classes. In our case, the ModuleNotFoundError is a subclass of the ImportError class.

You can see this in this screenshot from the docs:

You can also check this relationship using the issubclass() built-in function:

>>> issubclass(ModuleNotFoundError, ImportError)
True

Specifically, Python raises the ModuleNotFoundError if the module (e.g., selenium) cannot be found. If it can be found, there may be a problem loading the module or some specific files within the module. In those cases, Python would raise an ImportError.

If an import statement cannot import a module, it raises an ImportError. This may occur because of a faulty installation or an invalid path. In Python 3.6 or newer, this will usually raise a ModuleNotFoundError.

Related Videos

The following video shows you how to resolve the ImportError:

How to Fix : “ImportError: Cannot import name X” in Python?

The following video shows you how to import a function from another folder—doing it the wrong way often results in the ModuleNotFoundError:

How to Call a Function from Another File in Python?

How to Fix “ModuleNotFoundError: No module named ‘selenium’” in PyCharm

If you create a new Python project in PyCharm and try to import the selenium library, it’ll raise the following error message:

Traceback (most recent call last):
  File "C:/Users/.../main.py", line 1, in <module>
    import selenium
ModuleNotFoundError: No module named 'selenium'

Process finished with exit code 1

The reason is that each PyCharm project, per default, creates a virtual environment in which you can install custom Python modules. But the virtual environment is initially empty—even if you’ve already installed selenium on your computer!

Here’s a screenshot exemplifying this for the pandas library. It’ll look similar for selenium.

The fix is simple: Use the PyCharm installation tooltips to install Pandas in your virtual environment—two clicks and you’re good to go!

First, right-click on the pandas text in your editor:

Second, click “Show Context Actions” in your context menu. In the new menu that arises, click “Install Pandas” and wait for PyCharm to finish the installation.

The code will run after your installation completes successfully.

As an alternative, you can also open the Terminal tool at the bottom and type:

$ pip install selenium

If this doesn’t work, you may want to set the Python interpreter to another version using the following tutorial: https://www.jetbrains.com/help/pycharm/2016.1/configuring-python-interpreter-for-a-project.html

You can also manually install a new library such as selenium in PyCharm using the following procedure:

  • Open File > Settings > Project from the PyCharm menu.
  • Select your current project.
  • Click the Python Interpreter tab within your project tab.
  • Click the small + symbol to add a new library to the project.
  • Now type in the library to be installed, in your example Pandas, and click Install Package.
  • Wait for the installation to terminate and close all popup windows.

Here’s an analogous example:

Here’s a full guide on how to install a library on PyCharm.

  • How to Install a Library on PyCharm

While working as a researcher in distributed systems, Dr. Christian Mayer found his love for teaching computer science students.

To help students reach higher levels of Python success, he founded the programming education website Finxter.com. He’s author of the popular programming book Python One-Liners (NoStarch 2020), coauthor of the Coffee Break Python series of self-published books, computer science enthusiast, freelancer, and owner of one of the top 10 largest Python blogs worldwide.

His passions are writing, reading, and coding. But his greatest passion is to serve aspiring coders through Finxter and help them to boost their skills. You can join his free email academy here.

audible-activator.py works well, it stops to work when runned from aax2mp3

EDIT:
./aax2mp3_easy.sh <user> <pass> <file> first run output tail is:

Requirement already satisfied: requests in /usr/local/lib/python2.7/dist-packages 
Requirement already satisfied: selenium in /usr/local/lib/python2.7/dist-packages
Traceback (most recent call last):
  File "audible-activator-feature_login_as_arg/audible-activator.py", line 8, in <module>
    from selenium import webdriver
ModuleNotFoundError: No module named 'selenium' 

sudo ./aax2mp3_easy.sh <user> <pass> <file> first run output tail is:

Requirement already satisfied: requests in /usr/local/lib/python2.7/dist-packages
Requirement already satisfied: selenium in /usr/local/lib/python2.7/dist-packages
Traceback (most recent call last):
File "audible-activator-feature_login_as_arg/audible-activator.py", line 148, in
fetch_activation_bytes(username, password, options)
File "audible-activator-feature_login_as_arg/audible-activator.py", line 57, in fetch_activation_bytes
executable_path=chromedriver_path)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 75, in init
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 154, in init
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
(Driver info: chromedriver=2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881),platform=Linux 4.9.0-6-amd64 x86_64)

2018-03-03 02:19:06+0100 Decoding Player with auth code [*]...

Obviously no updates on both attempts

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

29.2k21 gold badges79 silver badges131 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,38219 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

4906 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,5282 gold badges16 silver badges23 bronze badges

answered Mar 19, 2020 at 8:11

Lebecca's user avatar

LebeccaLebecca

2,24612 silver badges31 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,8445 gold badges27 silver badges38 bronze badges

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

Samsul Islam's user avatar

Samsul Islam

2,5282 gold badges16 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

7781 gold badge12 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,5282 gold badges16 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.2k27 gold badges82 silver badges89 bronze badges

answered Aug 17, 2019 at 19:48

Gunjan Paul's user avatar

Gunjan PaulGunjan Paul

4935 silver badges11 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

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

29.2k21 gold badges79 silver badges131 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,38219 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

4906 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,5282 gold badges16 silver badges23 bronze badges

answered Mar 19, 2020 at 8:11

Lebecca's user avatar

LebeccaLebecca

2,24612 silver badges31 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,8445 gold badges27 silver badges38 bronze badges

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

Samsul Islam's user avatar

Samsul Islam

2,5282 gold badges16 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

7781 gold badge12 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,5282 gold badges16 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.2k27 gold badges82 silver badges89 bronze badges

answered Aug 17, 2019 at 19:48

Gunjan Paul's user avatar

Gunjan PaulGunjan Paul

4935 silver badges11 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

We can easily fix the error importerror no module named selenium by just installing the selenium python package using pip, conda etc. There is so many python package managers like pip, conda which can install the selenium package in one line. The another way to install the selenium python package is direct from the source. In this article, We will explore those ways and fix the error.

Here will see the different ways of installing the selenium package. Because you will not get this error while running the code after successful installation of the python package.

Installation of selenium using pip –

This is the most popular way of installing selenium is a pip. Use the below command for installation

pip install selenium

This will down the package and install the same in the required path for you. There are a few things related to pip is –

1.1  –  In some scenarios, It needs admin permission. Then you may add sudo with the above command.

sudo pip install selenium

1.2 – In Python 3, You may use the alternative command.

sudo pip3 install selenium

2 Installation of selenium using  Conda –

Just like pip, Conda is also a trusted python package manager. Use the below command for installing selenium using conda .

conda install -c conda-forge selenium

Importerror no module named selenium

Importerror no module named selenium

Selenium is really useful for web scraping and test automation for web tools. Selenium is more popular with java and python. In fact, java has more market share than python with selenium. It actually automates the driver, which can be leveraged in many use cases.

If you are still stuck in the same issue, please refer to the official guide of selenium python for installation. Please go through it if you are a selenium python beginner. It will cover the example codes for basic understanding with various browser support.

Thanks 

Data Science Learner 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.

0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии

А вот еще интересные материалы:

  • Яшка сломя голову остановился исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного где ошибка
  • Ошибка modulenotfounderror no module named psycopg2
  • Ошибка msvcr100 dll не обнаружен пожалуйста установите нужные библиотеки windows 10