Questions tagged [python-2to3]

2to3 is a tool for automated Python 2 to 3 code translation. Don't use this tag to ask about differences between Python 2 and Python 3. Use the [python-3.x] and [python-2.7] tags for that.

2to3 is a Python program that reads Python 2.x source code and applies a series of fixers to transform it into valid Python 3.x code. The standard library contains a rich set of fixers that will handle almost all code. 2to3 supporting library lib2to3 is, however, a flexible and generic library, so it is possible to write your own fixers for 2to3. lib2to3 could also be adapted to custom applications in which Python code needs to be edited automatically.

For more information, see the documentation at: http://docs.python.org/library/2to3.html

185 questions
3
votes
1 answer

Converting selenium.py to python 3 by 2to3

I'm trying to convert selenium.py written in python 2. As you see below I copied selenium.py to C:\Python32\Tools\Scripts> and after execution 2to3.py selenium.py I see that the file is the same. What Have I done wrong? Or from where I can…
user278618
  • 19,306
  • 42
  • 126
  • 196
3
votes
1 answer

AttributeError: 'DiGraph' object has no attribute '_node'

The code is written by someone else using Python 2.7.12, networkx 1.11, numpy 1.13.0, scipy 0.18.1, matplotlib 2.0.2. It consists of several self-made modules. I have converted the entire code to Python 3.x using "2to3" converter. I am running the…
kumar navneet
  • 31
  • 1
  • 1
  • 7
3
votes
1 answer

Python 2to3 warning What does it mean?

I am using 2to3 to convert a script. The only warning I get is: RefactoringTool: Line 716: You should use 'operator.mul(None)' here. Line 716 of the original script is: classes = repeat(None) I don't get where shall I use operator.mul(None). The…
alec_djinn
  • 10,104
  • 8
  • 46
  • 71
3
votes
4 answers

Document image dewarping script on Python 3.5

I'm trying to run the following script on windows: https://github.com/mzucker/page_dewarp. It requires scipy, numpy, pillow and OpenCV. I have no experience with python, I have downloaded WinPython (http://winpython.github.io/), which includes…
qwertxyz
  • 143
  • 1
  • 7
3
votes
2 answers

python 2to3 manual modification

Is there a way to change python2.x source code to python 3.x manually. I guess using lib2to3 this can be done but I don't know exactly how to do this ?
pkumar
  • 4,743
  • 2
  • 19
  • 21
3
votes
3 answers

2to3 conversion for strings

I have written a small Qt-based text editor for Python code that I embed in my application. Now I am going to switch to Python 3 and I want to help the users of my app with converting their code. I know that 2to3 can do most of the conversion for…
Maciek D.
  • 2,754
  • 1
  • 20
  • 17
3
votes
1 answer

TypeError: integer argument expected got float' Python 3.4

I get a error of a integer expected a float so I change it and then get the reverse saying a float can not be a integer. I had similar issues before and just changed it to have the int. I am learning via tutorials in python27 but have for the most…
john taylor
  • 1,080
  • 15
  • 31
3
votes
1 answer

Add custom fixer to lib2to3 after fixer has been written

I am working on writing a custom fixer for lib2to3, not to migrate code to Python 3, but to utilize the source code parsing functionality of lib2to3 rather than manually parsing source with regexs and the like. I've written a basic fixer at this…
Keyan P
  • 920
  • 12
  • 20
3
votes
2 answers

How to launch own 2to3 fixer?

I wrote own fixer, how can i run it? I don't find obvious way to do this. Only this: > cd /usr/lib/python2.7/lib2to3/fixes/ > ln -s path/to/my_fixer.py And then run it: > cd path/to/project > 2to3 -f my_fixer .
Pyt
  • 1,925
  • 2
  • 13
  • 10
3
votes
1 answer

Is there a way to run 2to3 with pip install?

I'm trying to maintain dependencies using pip install -r requirements.txt. However, some of required packages do not support Python 3 directly, but can be converted manually using 2to3. Is there a way to force pip to run 2to3 on those packages…
eigenein
  • 2,083
  • 3
  • 25
  • 43
3
votes
1 answer

What's the difference between 2to3-2.7 and 2to3-3.1?

My Ubuntu 12.04 stock python install has 2 programs for converting code to Python 3.x: 2to3-2.7 and 2to3-3.1. What's the difference?
drevicko
  • 14,382
  • 15
  • 75
  • 97
2
votes
0 answers

Python 2 to Python 3 Conversion: Can't find __main__ module in pyz

I am working on porting a python2 project to python3 while keeping the compatibility with python2. I started fixing small things: indentation, print calls, some imports using six etc. The Makefile creates a zip archive with the python header…
Teodor
  • 21
  • 3
2
votes
1 answer

Converting Django project from Python 2 to Python 3: How to fix Python int OverFlowError?

I am converting a Django website from Python 2 to Python 3. To do this, I ran 2to3 on the whole project. Now, upon running the server (which works fine in Python 2), an OverflowError occurs as shown in the first code block. The lower block shows the…
woefipuasd
  • 23
  • 4
2
votes
2 answers

Python-2to3: Safe Set of Fixers for Python 2 and 3

What subset of Python 2to3 fixers output valid Python 2 code? Rather than move to Python 3 all at once, I'd like to use 2to3 to get most of the way there, saving the really hairy stuff (e.g., unicode changes) for a later time or possibly using six…
speedplane
  • 15,673
  • 16
  • 86
  • 138
2
votes
1 answer

struct unpack (Type Error: a byte like object is required, not 'str"), Unpack a List?

Attempting to use script that was built in Python 2, and now use it in Python 3 without adding a version 2 onto system. For the script, the only error I get is related to a struct.unpack at this line.... def go_parse(rec_list): size =…
D-slr8
  • 99
  • 8