Home > Back-end >  Selenium cannot be found when running the python script from CommandLine
Selenium cannot be found when running the python script from CommandLine

Time:08-13

I'm using python to write a selenium script. Selenium is already installed and imported in my script and it is all fine when I run the script on Pycharm IDE, no issues or error.

But when I tried using cmd to run my script, it showed a error:

ModuleNotFoundError: No module named 'selenium'

Does anyone know what is the problem here?

CodePudding user response:

You might find something helpful here. Look at the comments on this post

If you need a library in a specific environment you need to install it in that environment. Pycharm likely maintains its own environments. Use the environment it created (look in your settings for "interpreter" and use that path when running Python) or install the library into the environment you're using. (sys is included in the standard library, so it's not a good point of comparison.)

CodePudding user response:

This error message executing the python script from commandline...

ModuleNotFoundError: No module named 'selenium'

...indicates that the Selenium library wasn't installed in your system disk but was installed with PyCharm's virtual environment, i.e. within:

C:\Users\user_name\PycharmProjects\project_name\venv

which your system isn't aware.

Solution

To execute the python script from CLI you need to install the Selenium library within your system disk using either of the following commands:

  • From commandline using pip (install):

    $pip install selenium
    
  • From commandline using pip3 (install or upgrade):

    $pip3 install -U selenium
    
  • Related