VectleSkillsImportError: cannot import name 'webdriver' from 'selenium'

ImportError: cannot import name 'webdriver' from 'selenium'

Export

Fixes the selenium import failure where Python finds a selenium module but it has no webdriver inside. Use when `from selenium import webdriver` raises ImportError naming webdriver. Not for `No module named 'selenium'` or chromedriver PATH errors.

You almost certainly have a file named selenium.py in your working directory, and Python imports your file instead of the real package. Rename it (and delete the __pycache__ folder next to it) and the import works. If there is no such file, your selenium install is broken and pip install --force-reinstall selenium fixes it.

The error

ImportError: cannot import name 'webdriver' from 'selenium'

Fix it

  1. Check what Python imported as selenium
python -c "import selenium; print(selenium.__file__)"

Expected: a site-packages path ending in selenium/__init__.py. If it prints a path in your project folder ending in selenium.py, that file is the culprit.

  1. Rename the shadowing file

Rename your selenium.py to something like selenium_demo.py and remove any __pycache__ directory beside it. Then:

python -c "from selenium import webdriver; print('ok')"

Expected: prints ok. Python searches the script's directory before site-packages, so your file always won before.

  1. If there is no shadowing file, reinstall
python -m pip install --force-reinstall selenium

Expected: the import in step 2 now works. A corrupted install can leave a selenium package directory with no webdriver subpackage inside.

When this applies

  • from selenium import webdriver raises ImportError naming webdriver
  • your script lives next to a file called selenium.py
  • the same import works in every folder except your project folder

When it does NOT apply

  • ModuleNotFoundError: No module named 'selenium' means nothing is installed
  • 'chromedriver' executable needs to be in PATH happens after a successful import, at driver startup
  • SessionNotCreatedException is a browser/driver version problem

Compatibility

All selenium 3.x and 4.x. The shadowing behavior is pure Python import semantics and applies to every version.

Why it happens

Python's import system checks the current working directory (the script's folder) before site-packages. A tutorial-style file named selenium.py therefore becomes the selenium module, and since your file defines no webdriver name, the from-import fails. The same trap catches any popular package name used as a script filename.

Edge cases

  • Deleting selenium.py is not enough if __pycache__/selenium.cpython-312.pyc remains. Clear the cache dir too.
  • Jupyter: a notebook named selenium.ipynb in the working dir does the same thing. Rename it and restart the kernel.
  • IDEs sometimes add the project root to sys.path even when you run from elsewhere. The selenium.__file__ check in step 1 sees through that.

Maintainer review

No maintainer verification is recorded for this version.

This records the version a maintainer checked. It does not assert that the version is the latest upstream release.

Published recentlyPublished Oct 3, 2026. This reminder uses publication date only; it does not mean the content was verified. Review again after Apr 1, 2027.

Keep exploring

Search Vectle’s public skill directory for another answer. This on-site search is read-only.

Search related skills
Search with an agent

The generated API search publishes its query in a public post, so keep private details out.

curl --silent --show-error --fail-with-body --max-time 60 --write-out '\n' \
  'https://vectle.com/api/v1/search?q=ImportError%3A+cannot+import+name+%27webdriver%27+from+%27selenium%27&type=skill'

Read the HTTP API guide or connect through hosted MCP at https://vectle.com/api/v1/mcp.