Home > Net >  ImportError: cannot import name 'build_py_2to3' from 'distutils.command.build_py'
ImportError: cannot import name 'build_py_2to3' from 'distutils.command.build_py'

Time:01-12

I tried to install bipwallet through pip but it says there is no 'build_py_2to3' in distutils

Defaulting to user installation because normal site-packages is not writeable
Collecting bipwallet
...
Collecting protobuf==3.0.0a3
  Using cached protobuf-3.0.0a3.tar.gz (88 kB)
  Preparing metadata (setup.py) ... 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 "/tmp/pip-install-q8v8yny3/protobuf_3f1a8b67130540ab9c93af7fe765918c/setup.py", line 29, in <module>
          from distutils.command.build_py import build_py_2to3 as _build_py
      ImportError: cannot import name 'build_py_2to3' from 'distutils.command.build_py' (/home/orkhan/.local/lib/python3.11/site-packages/setuptools/_distutils/command/build_py.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.

I tried to search in Google but it did not help. I also tried pip install --upgrade distutils thinking maybe it's just older version.

P.S. my python version 3.11

CodePudding user response:

It seems as though bipwallet or one of its dependencies (protobuf-3.0.0a3?) wants to use whatever version of setuptools is available rather than pinning a specific version. setuptools v58.0.0 has a breaking change, first included in Python 3.10, where build_py_2to3 was removed.

You have a couple options:

  1. Find the offending library and edit its setup.py to indicate that it should use setuptools<=57.5.0 and retry.
  2. Downgrade your Python installation to 3.9 to get a local version of setuptools prior to the breaking change.

Here are a couple other related posts/links to the issue you're seeing:

  • Related