ModuleNotFoundError: No module named 'pyquery'
Fixes the plain missing-module error for pyquery. Use when `from pyquery import PyQuery` fails with ModuleNotFoundError naming pyquery. Not for the lxml etree import failure underneath it.
pyquery is not installed in the running Python. Run python -m pip install pyquery. The PyPI name and the import name match (pyquery), so this is just a missing install.
The error
ModuleNotFoundError: No module named 'pyquery'Fix it
- Install pyquery
python -m pip install pyqueryExpected: Successfully installed pyquery-... with lxml and cssselect.
- Confirm
python -c "from pyquery import PyQuery; print(PyQuery('hi').text())"Expected: prints hi.
When this applies
- any pyquery import fails naming
pyquery - a fresh env for a jQuery-style scraping script
When it does NOT apply
cannot import name 'etree' from 'lxml'means pyquery IS installed but lxml is broken (Python 3.12 vs old lxml)cannot import name 'PyQuery' from 'pyquery'is the shadowing problem
Compatibility
pyquery 2.x. Needs lxml; on Python 3.12+ make sure lxml is 4.9.3+.
Why it happens
The package was never installed into the active interpreter. pyquery scripts move between machines often, and the import is the first thing that notices.
Edge cases
- If the import then fails on
etreefrom lxml, your lxml is too old for your Python. Upgrade lxml. - pyquery is a thin wrapper over lxml. If lxml itself will not install on your platform, pyquery cannot work either.
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.