Registry / devops / 2to3
library1.0pypypiunverified

2to3 is a Python program designed to automatically convert Python 2.x source code into Python 3.x compatible code. It achieves this by applying a series of 'fixers' that address common syntax and API changes between the two major Python versions. The PyPI package `2to3` (version 1.0, last updated September 2018) primarily provides the `2to3` command-line utility, which was historically part of the Python standard library. Its core component, `lib2to3`, has been deprecated since Python 3.11 and is slated for removal in Python 3.13, marking the tool's transition towards obsolescence for active development. As Python 2 reached its End-of-Life in January 2020, the utility's main relevance is for legacy codebase migrations.

pip install 2to3
INSTALL
IMPORT
SIG · 2TO3
2
2to3
devopspythonv1.0
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

2to3 (command-line tool)
This library is primarily used as a command-line tool.
The `2to3` tool is typically invoked from the shell, not imported as a Python module for direct code conversion. While its underlying library, `lib2to3`, exists, its API is unstable and deprecated for general use.

The `2to3` tool is executed from the command line, pointing it to Python 2.x source files or directories. The `-w` flag writes the changes back to the original files, creating a `.bak` backup. The `--output-dir` option allows writing converted files to a new location, often used with `-n` to prevent backup files and `-W` to write all files, even if unchanged.

# Save your Python 2 code to a file, e.g., 'my_python2_script.py' # Example content for my_python2_script.py: # print 'Hello, world!' # x = raw_input('Enter your name: ') # print 'Your name is', x # To see the changes without modifying the file: # 2to3 my_python2_script.py # To apply changes directly to the file (creates a .bak backup): # 2to3 -w my_python2_script.py # To convert an entire directory to a new output directory: # mkdir python3_version # 2to3 --output-dir=python3_version -W -n python2_codebase/
2to3 --version
Debug
Known issues
breakingThe underlying `lib2to3` library, which powers the `2to3` tool, was officially deprecated in Python 3.11 and is scheduled for removal in Python 3.13 (expected October 2024). This means the `2to3` PyPI package and the standalone tool may cease to function or be actively supported in newer Python environments.
fix
For new projects, avoid Python 2 entirely. For existing Python 2 codebases, migrate to Python 3 as soon as possible and manually address any remaining incompatibilities if `2to3` is no longer viable with your target Python 3 version. Consider alternatives like `python-modernize` for dual Python 2/3 compatibility if needed for a transition period, though Python 2 is EOL.
affects: Python 3.11+
gotcha`2to3` cannot automatically fix all Python 2 to Python 3 incompatibilities. Significant changes, such as those related to Unicode vs. bytes, reorganized standard library modules (e.g., `urllib`, `urllib2`), and certain semantic shifts, often require manual review and modification after conversion.
fix
Always thoroughly review the diffs generated by `2to3` and extensively test the converted Python 3 code. Be prepared to manually refactor code, especially for string/bytes handling, exception syntax (`except Exception as e`), and relocated standard library modules.
affects: All versions
gotchaThe `2to3` tool itself, relying on `lib2to3`, is unable to parse Python 3.10+ grammar due to the introduction of the new PEG parser in CPython. This limits its ability to convert Python 2 code if the `2to3` tool itself is being run on a very recent Python 3 interpreter (e.g., 3.10 and above) that it cannot parse.
fix
Run `2to3` using an older Python 3 interpreter (e.g., Python 3.9 or earlier) if encountering parsing issues with newer Python versions, or manually port the code. Given Python 2 is EOL, a full manual port for problematic sections might be more robust.
affects: Python 3.10+
Upgrade
Version history
1.0latest on PyPI · released Sep 7, 2018
Audit
Dependencies

No dependency data recorded yet.

Agent activity
55 hits · last 30 days
node
46
Amazon
1
OpenAI (training)
1
Resources
2to3 — pip install 2to3 · libregistry