PythonCharmers / python-future

Easy, clean, reliable Python 2/3 compatibility
http://python-future.org
MIT License
1.17k stars 291 forks source link

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

Open prasanta2018 opened 2 years ago

prasanta2018 commented 2 years ago

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.

Mike-Allen commented 2 years ago

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 was then able to import builtins in Python 2.7. Edit: Actually "from future import builtins" was what worked.