Posts: 6
Threads: 2
Joined: Oct 2023
Oct-05-2023, 11:27 AM
Hello Fellow Python users i have a frontend code and other backend,libraries that i need to convert them from python2 to python3 but while trying using pip 2to3 i facking errors and i dont know how to use modernize or futurize functions, can someone help me with the conversion process. I'm attaching the screenshot of the error while using pip install.
Attached Files
Thumbnail(s)
Posts: 7,093
Threads: 122
Joined: Sep 2016
Oct-05-2023, 11:45 AM
(This post was last modified: Oct-05-2023, 11:46 AM by snippsat.)
pip did drop support for Python 2.7 in version 21.0.
So have to install a older version pip install pip==20.0
There is no need to upgrade Python 2.7,if migrate older code you use 2to3 from a Python 3 version.
So need have Python 3 version where test(and use tool eg 2to3) that the older 2.7 code works.
Posts: 6
Threads: 2
Joined: Oct 2023
(Oct-05-2023, 11:45 AM)snippsat Wrote: pip did drop support for Python 2.7 in version 21.0.
So have to install a older version pip install pip==20.0
There is no need to upgrade Python 2.7,if migrate older code you use 2to3 from a Python 3 version.
So need have Python 3 version where test(and use tool eg 2to3) that the older 2.7 code works.
sorry I'm not so good at it, what exactly should i do now just run the code on python3 version and check whether it runs or not??
Posts: 7,093
Threads: 122
Joined: Sep 2016
Oct-05-2023, 12:32 PM
(This post was last modified: Oct-05-2023, 12:32 PM by snippsat.)
(Oct-05-2023, 11:58 AM)zuri Wrote: what exactly should i do now just run the code on python3 version and check whether it runs or not?? Yes that's be the first step,you are on Windows install eg Python 3.11 it comes with 2to3 in ...\Python311\Tools\scripts\2to3.py
There is also a online version Python 2 to 3 converter
If i do a demo,i just use from the folder i posted where i save words.py .
C:\Python311\Tools\scripts
λ python 2to3.py -w words.py
C:\Python311\Tools\scripts\2to3.py:3: DeprecationWarning: lib2to3 package is deprecated and may not be able to parse Python 3.10+
from lib2to3.main import main
RefactoringTool: Skipping optional fixer: buffer
RefactoringTool: Skipping optional fixer: idioms
RefactoringTool: Skipping optional fixer: set_literal
RefactoringTool: Skipping optional fixer: ws_comma
RefactoringTool: Refactored words.py
--- words.py (original)
+++ words.py (refactored)
@@ -4,4 +4,4 @@
if len(w) <= 3:
filtered_words.append(w)
-print filtered_words
+print(filtered_words)
RefactoringTool: Files that were modified:
RefactoringTool: words.py # words.py
words = ['eagle', 'albatross', 'mouse', 'dog', 'tiger']
filtered_words = []
for w in words:
if len(w) <= 3:
filtered_words.append(w)
print(filtered_words) The code before that had clear change which is print .
# words.py
words = ['eagle', 'albatross', 'mouse', 'dog', 'tiger']
filtered_words = []
for w in words:
if len(w) <= 3:
filtered_words.append(w)
print filtered_words
Posts: 6
Threads: 2
Joined: Oct 2023
(Oct-05-2023, 12:32 PM)snippsat Wrote: (Oct-05-2023, 11:58 AM)zuri Wrote: what exactly should i do now just run the code on python3 version and check whether it runs or not?? Yes that's be the first step,you are on Windows install eg Python 3.11 it comes with 2to3 in ...\Python311\Tools\scripts\2to3.py
There is also a online version Python 2 to 3 converter
If i do a demo,i just use from the folder i posted where i save words.py .
C:\Python311\Tools\scripts
λ python 2to3.py -w words.py
C:\Python311\Tools\scripts\2to3.py:3: DeprecationWarning: lib2to3 package is deprecated and may not be able to parse Python 3.10+
from lib2to3.main import main
RefactoringTool: Skipping optional fixer: buffer
RefactoringTool: Skipping optional fixer: idioms
RefactoringTool: Skipping optional fixer: set_literal
RefactoringTool: Skipping optional fixer: ws_comma
RefactoringTool: Refactored words.py
--- words.py (original)
+++ words.py (refactored)
@@ -4,4 +4,4 @@
if len(w) <= 3:
filtered_words.append(w)
-print filtered_words
+print(filtered_words)
RefactoringTool: Files that were modified:
RefactoringTool: words.py # words.py
words = ['eagle', 'albatross', 'mouse', 'dog', 'tiger']
filtered_words = []
for w in words:
if len(w) <= 3:
filtered_words.append(w)
print(filtered_words) The code before that had clear change which is print .
# words.py
words = ['eagle', 'albatross', 'mouse', 'dog', 'tiger']
filtered_words = []
for w in words:
if len(w) <= 3:
filtered_words.append(w)
print filtered_words where should i run it? in cmnd prompt or on ide of pyth3?
Posts: 7,093
Threads: 122
Joined: Sep 2016
(Oct-05-2023, 12:41 PM)zuri Wrote: where should i run it? in cmnd prompt or on ide of pyth3? From command line cmd ,i use cmder but commands is the same.
Could also install 2to3,then if work from anywhere in cmd.
C:\
λ python --version
Python 3.11.3
C:\
λ pip -V
pip 23.2.1 from C:\python311\Lib\site-packages\pip (python 3.11)
C:\
λ pip install 2to3 --upgrade
Collecting 2to3
Downloading 2to3-1.0-py3-none-any.whl (1.7 kB)
Installing collected packages: 2to3
Successfully installed 2to3-1.0
C:\
λ 2to3 --help
Usage: 2to3 [options] file|dir ...
Options:
-h, --help show this help message and exit
-d, --doctests_only Fix up doctests only
-f FIX, --fix=FIX Each FIX specifies a transformation; default: all
-j PROCESSES, --processes=PROCESSES
Run 2to3 concurrently
-x NOFIX, --nofix=NOFIX
Prevent a transformation from being run
-l, --list-fixes List available transformations
-p, --print-function Modify the grammar so that print() is a function
-e, --exec-function Modify the grammar so that exec() is a function
-v, --verbose More verbose logging
--no-diffs Don't show diffs of the refactoring
-w, --write Write back modified files
-n, --nobackups Don't write backups for modified files
-o OUTPUT_DIR, --output-dir=OUTPUT_DIR
Put output files in this directory instead of overwriting the input files. Requires -n.
-W, --write-unchanged-files
Also write files even if no changes were required (useful with --output-dir); implies
-w.
--add-suffix=ADD_SUFFIX
Append this string to all output filenames. Requires -n if non-empty. ex: --add-
suffix='3' will generate .py3 files.
Posts: 6
Threads: 2
Joined: Oct 2023
(Oct-05-2023, 01:59 PM)snippsat Wrote: (Oct-05-2023, 12:41 PM)zuri Wrote: where should i run it? in cmnd prompt or on ide of pyth3? From command line cmd ,i use cmder but commands is the same.
Could also install 2to3,then if work from anywhere in cmd.
C:\
λ python --version
Python 3.11.3
C:\
λ pip -V
pip 23.2.1 from C:\python311\Lib\site-packages\pip (python 3.11)
C:\
λ pip install 2to3 --upgrade
Collecting 2to3
Downloading 2to3-1.0-py3-none-any.whl (1.7 kB)
Installing collected packages: 2to3
Successfully installed 2to3-1.0
C:\
λ 2to3 --help
Usage: 2to3 [options] file|dir ...
Options:
-h, --help show this help message and exit
-d, --doctests_only Fix up doctests only
-f FIX, --fix=FIX Each FIX specifies a transformation; default: all
-j PROCESSES, --processes=PROCESSES
Run 2to3 concurrently
-x NOFIX, --nofix=NOFIX
Prevent a transformation from being run
-l, --list-fixes List available transformations
-p, --print-function Modify the grammar so that print() is a function
-e, --exec-function Modify the grammar so that exec() is a function
-v, --verbose More verbose logging
--no-diffs Don't show diffs of the refactoring
-w, --write Write back modified files
-n, --nobackups Don't write backups for modified files
-o OUTPUT_DIR, --output-dir=OUTPUT_DIR
Put output files in this directory instead of overwriting the input files. Requires -n.
-W, --write-unchanged-files
Also write files even if no changes were required (useful with --output-dir); implies
-w.
--add-suffix=ADD_SUFFIX
Append this string to all output filenames. Requires -n if non-empty. ex: --add-
suffix='3' will generate .py3 files. when Im trying to get the version info this is what im getting even though i installed the python 3 version
Attached Files
Thumbnail(s)
Posts: 7,093
Threads: 122
Joined: Sep 2016
Oct-05-2023, 02:40 PM
(This post was last modified: Oct-05-2023, 02:40 PM by snippsat.)
Look this tutorial .
Install this page Windows installer (64-bit) Windows Recommended
So you add to Path under install,if that not work you look under Fixing Path if needed .
How to change Environment Variables Path
So as this in this image just that you add path to where you have installed Python 3.11.
Then test in cmd again,also my need to restart Pc.
|