Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

pip install Cython succeeded, but the shell cannot find cythonize

Errorcythonize: command not found

Short 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.

  • Applies to Python 3.10 to 3.13, pip 24, Cython 3.x, Ubuntu 22.04 and 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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"
  2. 2Match what you see, then jump to its fix

    1. 1pip warned that scripts went to a directory outside PATH, and cythonize exists in ~/.local/binThe user-install bin folder is not on PATHFix
    2. 2pip 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. 3Once cythonize runs, the build step stops with a compiler or Python.h errorcythonize starts, then the build fails because there is no C compilerFix

What does the error look like?

  • cythonize: command not found
  • a 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 ~/.profile

3Verify

The shell now resolves the command.

command -v cythonize && cythonize --help | head -n 3

Confirmed by packaging.python.org

Did this fix it?

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 Cython

3Verify

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 cython

Confirmed by pip.pypa.io

Did this fix it?

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.pyx

3Verify

A compiled extension module appears next to the .pyx file.

ls yourmod*.so

Confirmed by cython.readthedocs.io

Did this fix it?

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:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.