pip install Cython succeeded, but the shell cannot find cythonize
cythonize: command not foundShort answer
pip put the cythonize script in a folder your shell does not search. With a user install that folder is ~/.local/bin. Find it with python3 -m site --user-base, add its bin directory to PATH, or call the tool through the same Python that installed it. A missing C compiler is a separate, later failure.
Fix it fast
1Find out which cause you have
Ask pip where it put Cython, then list the bin folder that belongs to your Python user base. If cythonize is there, the install worked and only PATH is wrong.
python3 -m pip show -f Cython | head -n 12 ls "$(python3 -m site --user-base)/bin"2Match what you see, then jump to its fix
- 1
pip warned that scripts went to a directory outside PATH, and cythonize exists in ~/.local/binThe user-install bin folder is not on PATHFix - 2
pip show Cython finds the package for one interpreter, while python3 -c 'import Cython' fails or reports another pathpip3 and python3 belong to different installsFix - 3
Once cythonize runs, the build step stops with a compiler or Python.h errorcythonize starts, then the build fails because there is no C compilerFix
- 1
What does the error look like?
cythonize: command not founda pip warning that a script was installed to a directory outside PATH
Cause 1 of 3
The user-install bin folder is not on PATH
1Check
On Linux the user base is normally ~/.local, and scripts installed with --user go into its bin directory. Check whether your PATH contains it.
echo "$PATH" | tr ':' '\n' | grep -n "\.local/bin"
ls -l "$(python3 -m site --user-base)/bin/cythonize"2Fix
Add the bin folder to PATH. The Python Packaging User Guide suggests doing it permanently in ~/.profile.
echo 'export PATH="$(python3 -m site --user-base)/bin:$PATH"' >> ~/.profile
source ~/.profile3Verify
The shell now resolves the command.
command -v cythonize && cythonize --help | head -n 3Confirmed by packaging.python.org
Cause 2 of 3
pip3 and python3 belong to different installs
1Check
A bare pip3 can belong to another Python than the python3 you use. pip's own guide recommends python -m pip, which runs pip with the interpreter you named.
which -a python3 pip3
python3 -m pip --version
python3 -c "import Cython, sys; print(Cython.__file__, sys.executable)"2Fix
Install with the interpreter you build with, so the script lands next to that interpreter's user base.
python3 -m pip install --user Cython3Verify
Cython imports under the same python3, and the script is in its user base.
python3 -c "import Cython; print(Cython.__version__)"
ls "$(python3 -m site --user-base)/bin" | grep cythonConfirmed by pip.pypa.io
Cause 3 of 3
cythonize starts, then the build fails because there is no C compiler
1Check
Cython translates .pyx to C and then compiles it. Its install guide says a C compiler is required and, on Ubuntu or Debian, that Python's header files are needed too.
gcc --version
python3 -c "import sysconfig, os; print(os.path.exists(sysconfig.get_paths()['include'] + '/Python.h'))"2Fix
Install the compiler and the Python headers, then run the build again.
sudo apt-get update
sudo apt-get install -y build-essential python3-dev
cythonize -a -i yourmod.pyx3Verify
A compiled extension module appears next to the .pyx file.
ls yourmod*.soConfirmed by cython.readthedocs.io
How do I stop it coming back?
- Call tools through the interpreter you mean: python3 -m pip, not a bare pip3.
- Keep project tools in a virtual environment and activate it, so its bin folder is first on PATH.
- Read the last lines of pip's output; the PATH warning names the exact folder.
- Install build-essential and python3-dev on any build machine before compiling extensions.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- stegnor.comMy company site: 804 pages from a Python and Jinja generator, with 15 free browser tools.
- MenuloA restaurant discovery platform in Germany, kept current by a Python ingestion pipeline.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
Servers
pip install confluent-kafka fails because librdkafka/rdkafka.h is missing
pip stops while building confluent-kafka from source
The error means pip is compiling confluent-kafka from source, and the compiler cannot find the librdkafka C headers.
3 causes, each with a fixServers
cv2.imshow raises 'not implemented' because the wrong OpenCV package is installed
cv2.imshow() works in one environment and fails in another
The headless OpenCV packages are built without any GUI code, so cv2.imshow cannot open a window.
2 causes, each with a fixServers
Django returns a 500 behind Gunicorn and the traceback is nowhere
The traceback shows locally with runserver but not under Gunicorn
With DEBUG set to False, Django's default logging does not print errors to the console.
2 causes, each with a fixServers
Docker build fails with apk: not found in a Python or Ubuntu image
/bin/sh: 1: apk: not found
apk is the package manager of Alpine Linux only.
2 causes, each with a fixServers
You cannot pip install packages inside an Ubuntu Docker container
error: externally-managed-environment
If pip is missing, install the python3-pip package with apt, in the same RUN as apt-get update.
3 causes, each with a fixServers
A PyInstaller app says GLIBC not found on another Linux machine
version `GLIBC_2.35' not found (required by /tmp/_MEIqx6YRS/libpython3.10.so.1.0)
PyInstaller does not bundle libc.
2 causes, each with a fix