0

I want to open my Python file through CMD. This file uses the Selenium module, but when I try to execute it in CMD, I get an error saying 'No Module named 'selenium'.' However, I have already installed the Selenium module, and when I execute it in an editor like Visual Studio Code, the code runs fine. What could be wrong?

  • Is the python binary that you use in the CMD the same python binary as associated in the VS Code environment? – ewokx Jun 09 '23 at 08:14
  • Your editor may use virtual environments (venv) for managing dependencies and Python versions. A dependency like selenium installed in a venv may not me available globally or in another venv. Check that you activated the right environment before trying to run your script. – The Coding Penguin Jun 09 '23 at 08:16
  • Execute `pip freeze` to check the versions of your libraries. – LoukasPap Jun 09 '23 at 08:19

1 Answers1

0

This question could be a duplicate of Python error "ImportError: No module named"

HINT: if you have installed the Selenium module successfully but are encountering an error when running your Python file through CMD, it is likely due to a mismatch between the Python environment being used by CMD and the one used by Visual Studio Code.

  1. To check your python environment just launch in your CMD

python --version

and check that it displays the correct Python version.

  1. In Visual Studio Code, you can check the Python interpreter used by opening the command palette (Ctrl+Shift+P) and searching for "Python: Select Interpreter." Ensure that the same Python environment is selected in both places.
Mena
  • 16
  • 2