pythonubuntupipdistutils

pip of python installed via deadsnakes, shows "no module named distutils" error


When installing python using deadsnakes ppa, and using pip on it like in the following example

python3.12 -m pip install django

will result in the following error

  File "/usr/lib/python3/dist-packages/pip/_internal/locations/_distutils.py", line 9, in <module>
    from distutils.cmd import Command as DistutilsCommand
ModuleNotFoundError: No module named 'distutils'

Solution

  • Short answer

    Run

    sudo apt install python3.12-distutils
    

    and this should solve your problem InshaAllah

    Long Answer

    When installing any python version using the deadsnakes ppa, you won't install an important package called distutils which is required for pip to run, if you have any other version other than python3.12, than use the following format

    sudo apt install python{version}-distutils