| title | python-venv: ModuleNotFoundError for tiktoken (and friends) | |||||
|---|---|---|---|---|---|---|
| domain | python | |||||
| tags |
|
|||||
| status | published | |||||
| lang | en | |||||
| source | uncledad96-glitch | |||||
| translated_from | lessons/contrib/python-venv-tiktoken-module-not-found.md | |||||
| created | 2026-07-22 | |||||
| updated | 2026-07-22 | |||||
| confidence | 0.9 |
import tiktoken (or another wheel-heavy package) fails with ModuleNotFoundError even after pip install, usually inside an agent venv.
- Install went to a different Python than the one running the script.
- venv not activated in the job environment.
- Build isolation / missing wheel on arch → silent fallback install failed.
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -U pip
python -m pip install tiktoken
python -c "import tiktoken; print(tiktoken.__file__)"Pin the interpreter in systemd/cron:
/home/you/proj/.venv/bin/python -c "import tiktoken"If wheels fail:
python -m pip install --only-binary=:all: tiktoken || \
python -m pip install tiktoken --no-cache-dir.venv/bin/python -c "import tiktoken; enc=tiktoken.get_encoding('cl100k_base'); print(len(enc.encode('hi')))"- Always
python -m pipwith the same binary you execute. - Log
sys.executableat job start for overnight agents.