ImportError: No module named 'selenium'

后端 未结 18 2144
时光取名叫无心
时光取名叫无心 2020-12-03 00:54

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/Pyt

相关标签:
18条回答
  • 2020-12-03 01:02

    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.

    0 讨论(0)
  • 2020-12-03 01:04

    Navigate to your scripts folder in Python directory (C:\Python27\Scripts) and open command line there (Hold shift and right click then select open command window here). Run pip install -U selenium
    If you don't have pip installed, go ahead and install pip first

    0 讨论(0)
  • 2020-12-03 01:06

    For python3, on a Mac you must use pip3 to install selenium.

    sudo pip3 install selenium
    
    0 讨论(0)
  • 2020-12-03 01:07

    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 !!

    0 讨论(0)
  • 2020-12-03 01:07

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

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

    python -m venv <name_of_virtual_env> (Windows Only)

    then activate the virtual environment with source <name_of_virtual_env>/bin/activate (for MacOS) and venv\Scripts\Activate.ps1 (for Windows powershell) or venv\Scripts\activate.bat (for Windows cmd). then 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.

    0 讨论(0)
  • 2020-12-03 01:08

    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.

    0 讨论(0)
提交回复
热议问题