简体   繁体   中英

Selenium cannot be found when running the python script from CommandLine

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?

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.)

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, ie 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM