0

I get the following error when importing gmusicapi in Python 2.7 on a Buildroot Linux system:

>>> import gmusicapi
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "gmusicapi/__init__.py", line 4, in <module>
    from gmusicapi.clients import Webclient, Musicmanager, Mobileclient
  File "gmusicapi/clients/__init__.py", line 4, in <module>
    from gmusicapi.clients.webclient import Webclient
  File "gmusicapi/clients/webclient.py", line 5, in <module>
    from past.builtins import basestring
  File "past/__init__.py", line 88, in <module>
    from past.translation import install_hooks as autotranslate
  File "past/translation/__init__.py", line 41, in <module>
    from lib2to3.pgen2.parse import ParseError
ImportError: No module named lib2to3.pgen2.parse

Python can't find lib2to3. Neither can I ;-). Is there anywhere I can download this library? I'm using Buildroot, so I can't simply do pip installs.

This is not a duplicate of: How to use/install python 2to3?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
svenema
  • 1,766
  • 2
  • 23
  • 45
  • 2
    According to the [docs](https://docs.python.org/2/library/2to3.html), "2to3 will usually be installed with the Python interpreter as a script. It is also located in the `Tools/scripts` directory of the Python root." – ForceBru Jan 17 '18 at 16:36
  • 1
    What OS is this? How was Python installed? `lib2to3` is part of the *standard library*, and should have been installed automatically. For example, on Ubuntu, I'd expect the [`libpython2.7-stdlib` package](https://packages.ubuntu.com/search?suite=default&section=all&arch=any&keywords=libpython2.7-stdlib&searchon=names) (which contains `lib2to3`) to have been installed as a dependency of `python2.7`. – Martijn Pieters Jan 17 '18 at 16:45
  • @ForceBru: I don't have this directory, also, I'd expect not a tool but a Python library, because Python code imports it. – svenema Jan 17 '18 at 16:46
  • @MartijnPieters: Linux (Buildroot). Maybe it's in a library which has a misleading name, but there is nothing like lib2to3 or anything that points in that direction. – svenema Jan 17 '18 at 16:47
  • @svenema, if your installation has the script, it must also have the library. If it doesn't, make sure you're using the official latest Python 2.7. – ForceBru Jan 17 '18 at 16:47
  • 1
    Then this looks relevant: https://github.com/buildroot/buildroot/blob/master/package/python/0018-Add-an-option-to-disable-lib2to3.patch – Martijn Pieters Jan 17 '18 at 22:19

3 Answers3

2

lib2to3 is a standard library, normally included with Python. However, the buildroot build system explicitly removes it.

I'm not certain if Buildroot actually lets you disable their patch; the python.mk file appears to hardcode the flag:

PYTHON_CONF_OPTS += \
    --without-cxx-main \
    --without-doc-strings \
    --with-system-ffi \
    --disable-pydoc \
    --disable-test-modules \
    --disable-lib2to3 \
    --disable-gdbm \
    --disable-tk \
    --disable-nis \
    --disable-dbm \
    --disable-pyo-build \
    --disable-pyc-build

and I don't see an option to add --enable-lib2to3 to override that. You may want to check with the Buildroot community if this is at all an option. Otherwise, I'd just edit that make file.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
0

Workaround: patching the past library (source of the problem):

--- past/translation/__init__.py.orig   2017-09-24 08:23:47.646644743 +0200
+++ past/translation/__init__.py    2018-01-01 10:31:36.584576652 +0100
@@ -38,8 +38,32 @@
 import os
 import sys
 import copy
-from lib2to3.pgen2.parse import ParseError
-from lib2to3.refactor import RefactoringTool
+
+try:
+    from lib2to3.pgen2.parse import ParseError
+
+except ImportError:
+
+    class ParseError(SyntaxError):
+        pass
+
+try:
+    from lib2to3.refactor import RefactoringTool
+
+except ImportError:
+
+    class RefactoringTool:
+
+        def __init__(self, *args, **kwargs):
+            self._args = [repr(a) for a in args]
+            self._args += ["{}={!r}".format(k, v) for k, v in kwargs.items()]
+
+        def __repr__(self):
+            return "{}({})".format(self.__class__.__name__, ", ".join(self._args))
+
+        def refactor_string(self, *args, **kwargs):
+            raise NotImplementedError("dummy RefactoringTool")
+

 from libfuturize import fixes

found here: https://github.com/PythonCharmers/python-future/issues/209

If someone can point me to a downloadable lib2to3 I'll accept that answer, for now this workaround will do the trick.

svenema
  • 1,766
  • 2
  • 23
  • 45
0

I resolved this issue by running below command on my Ubuntu 20.04 machine: sudo apt-get install -y python3.7-lib2to3

Jill
  • 47
  • 8