Skip to content

**builtins** is not available in python2.7 #604

Description

@prasanta2018

I'm working on the migration of my scripts from py2 to py3. So using the futurize tool.
as mentioned in the feature section of the git page "future.builtins package (also available as builtins on Py2) provides backports and remappings for 20 builtins with different semantics on Py3 versus Py2" but the case is builtins is not available in python2.7

`Python 2.7.17 (default, Feb 5 2022, 02:29:07)
[GCC 9.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.

from builtins import str
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named builtins
`

Since I used futurize tool, it imported "from builtins import objects" in my script but now this compatible with py3 not py2. how can I make compatible with both version for the builtin module. please help.

Activity

  1. Mike-Allen commented on Apr 13, 2022

    @Mike-Allen

    I ran into the same problem. After lots of digging I noticed that the package is installed in the /usr/lib/python3/dist-packages/ directory but not in the /usr/lib/python2.7/dist-packages/ directory.

    When Python 2.7 went EOL pip stopped working for Python 2 packages.

    In order to install this package for Python 2.7:

    • I downloaded the package as python-future-master.zip from the main code page
    • I created, as root, the /usr/lib/python2.7/dist-packages/future directory
    • I extracted the python-future-master.zip file's /src/future directory to /usr/lib/python2.7/dist-packages/future

    I was then able to import builtins in Python 2.7.
    Edit: Actually "from future import builtins" was what worked.

    • To import from builtins one must use: from future.builtins import bytes
    • Time will tell if there are other problems.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions