`pip install` Gives Error on Some Packages

Question:

Some packages give errors when I try to install them using pip install. This is the error when I try to install chatterbot, but some other packages give this error as well:

pip install chatterbot
Collecting chatterbot
  Using cached ChatterBot-1.0.5-py2.py3-none-any.whl (67 kB)
Collecting pint>=0.8.1
  Downloading Pint-0.19.2.tar.gz (292 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 292.0/292.0 kB 1.6 MB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Collecting pyyaml<5.2,>=5.1
  Using cached PyYAML-5.1.2.tar.gz (265 kB)
  Preparing metadata (setup.py) ... done
Collecting spacy<2.2,>=2.1
  Using cached spacy-2.1.9.tar.gz (30.7 MB)
  Installing build dependencies ... error
  error: subprocess-exited-with-error

  × pip subprocess to install build dependencies did not run successfully.
  │ exit code: 1
  ╰─> [35 lines of output]
      Collecting setuptools
        Using cached setuptools-65.0.1-py3-none-any.whl (1.2 MB)
      Collecting wheel<0.33.0,>0.32.0
        Using cached wheel-0.32.3-py2.py3-none-any.whl (21 kB)
      Collecting Cython
        Using cached Cython-0.29.32-py2.py3-none-any.whl (986 kB)
      Collecting cymem<2.1.0,>=2.0.2
        Using cached cymem-2.0.6-cp310-cp310-win_amd64.whl (36 kB)
      Collecting preshed<2.1.0,>=2.0.1
        Using cached preshed-2.0.1.tar.gz (113 kB)
        Preparing metadata (setup.py): started
        Preparing metadata (setup.py): finished with status 'error'
        error: subprocess-exited-with-error

        python setup.py egg_info did not run successfully.
        exit code: 1

        [6 lines of output]
        Traceback (most recent call last):
          File "<string>", line 2, in <module>
          File "<pip-setuptools-caller>", line 34, in <module>
          File "C:UsersogulsAppDataLocalTemppip-install-qce7tdofpreshed_546a51fe26c74852ab50db073ad57f1fsetup.py", line 9, in <module>
            from distutils import ccompiler, msvccompiler
        ImportError: cannot import name 'msvccompiler' from 'distutils' (C:UsersogulsAppDataLocalProgramsPythonPython310libsite-packagessetuptools_distutils__init__.py)
        [end of output]

        note: This error originates from a subprocess, and is likely not a problem with pip.
      error: metadata-generation-failed

      Encountered error while generating package metadata.

      See above for output.

      note: This is an issue with the package mentioned above, not pip.
      hint: See above for details.
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

I don’t specifically know which packages cause this error, a lot of them install without any problems.

I have tried updating pip, changing environment variables and other possible solutions I’ve found on the internet, but nothing seems to work.

Edit: The package I am trying to install supports my Python version.

Asked By: oas333

||

Answers:

The real error in your case is:

ImportError: cannot import name 'msvccompiler' from 'distutils'

It occured because setuptools has broken distutils in version 65.0.0 (and has already fixed it in version 65.0.2). According to your log, the error occured in your global setuptools installation (see the path in error message), so you need to update it with the following command:

pip install -U setuptools

Those packages, however, may still not get installed or not work properly as the module causing this error doesn’t support compiler versions needed for currently supported versions of Python.

Answered By: EvgenKo423

Same thing happened with me, it was basically pip’s version problem.
Try upgrading pip to latest version –22.3.1 and downgrade the python version from latest version –3.10.00 to 3.9.13…

pip --version check for pip’s version

pip install notebook --upgrade -command to update pip to latest version

This worked for me

Answered By: UTKARSH JOSHI

From my experience, it’s an issue with Python3.10. I went nuts with these errors and then tried both upgrade and downgrade. Works perfect with Python 3.11 or 3.8. (can’t add a comment, hence…)

Answered By: Amina Nasrin