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
2
votes
2 answers

ImportError: cannot import name getoutput

I am using future to port code from Python 2 to Python 3. Upon futurizing getoutput, the import changes from from commands import getoutput to from subprocess import getoutput And my code uses getoutput in testing a requirements file. However,…
Deesha
  • 538
  • 8
  • 27
2
votes
0 answers

Python 2to3 Converted Python Package Does Not Find Script

I have both Python 2.7 and 3.5 installed in Debian Stretch on my 64bit Linux platform. I have installed PyChem (http://pychem.sourceforge.net/), written in Python2 after converting the python files using the 2to3 script. There were no warning or…
Steve
  • 153
  • 2
  • 13
2
votes
3 answers

Should I convert dict.keys() into list(dict.keys()) for iteration in Python3?, 2to3 suggests converting that

I am doing a migration, Python2 to Pytnon3 with 2to3. (Python2.7.12 and Python3.5.2 exactly) While doing the migration, 2to3 suggests I use type-cast like the below. a = {1: 1, 2: 2, 3: 3} for i in a.keys(): ----> for i in list(a.keys()): …
SangminKim
  • 8,358
  • 14
  • 69
  • 125
2
votes
1 answer

duckduckgo module not working in python 3.4.4

Hi I got the following module from here import urllib import urllib2 import json as j import sys __version__ = 0.242 def query(query, useragent='python-duckduckgo '+str(__version__), safesearch=True, html=False, meanings=True, **kwargs): """ …
Vin
  • 729
  • 9
  • 15
2
votes
2 answers

brew install python for scrapy - symlink & permission issues

I'm following the Scrapy installation guide to install a fresh copy of python (2.7.11) despite I already have 2.6, 2.7.10 and 3.4.0. The installation was going fine until the final step with these errors ==> Pouring…
rockhammer
  • 957
  • 2
  • 13
  • 38
2
votes
2 answers

bash equivalent for os.walk?

I am using 2to3 to fix my script library, and it seems to be a command line thing, not a shell thing. I want to do all files from /home/me/scripts downward, assuming they end in .py. Is there an easy way to do 2to3 -y filename for each file under my…
codyc4321
  • 9,014
  • 22
  • 92
  • 165
2
votes
2 answers

Is there anyway to install twain module in python 3

I want to install the Python TWAIN module in Python 3. But in the docs it says: Python versions 2.1 through 2.5 are supported. Can I convert it using 2to3?
Cahit Yıldırım
  • 499
  • 1
  • 10
  • 26
2
votes
2 answers

Problem regarding 3.0's "hashlib" module

I've been working on getting a 2.5 module ported to 3.0, mostly for my own education, when I've gotten stuck. The class "Builder" has as its init: def __init__(self, **options): self._verifyOptions(options) self._options = options …
J.T. Hurley
  • 521
  • 9
  • 12
2
votes
0 answers

Porting a Python 2.X based project to Python 3

I want to port a web application scanning framework from Python 2.6.5-2.7.3 to Python 3 without causing much harm to the compatibility with Python 2.6+. I have read briefly about six: Python 2 and 3 Compatibility Library and python-modernize. The…
2
votes
2 answers

Using 2to3 python in windows

I am fairly new to programming and have been learning python on codecademy. I would like to convert a python 2x program to python 3x using 2to3 on the command line but have no idea how to do it. I have looked at various other questions and articles…
Tom
  • 145
  • 2
  • 6
2
votes
1 answer

2to3 range(...) -> list(range(...))

I know python 2to3 changes all xrange to range and I don't see any problem with this. My question is about how it changes range(...) into list(range(...)): is it dumb and just blindly search and replaces them all, or is it smart enough to tell when…
wim
  • 338,267
  • 99
  • 616
  • 750
1
vote
0 answers

nosetests: error: no such option: --profile-restrict

I am migrating from python2 to python3 and facing problems with migrating nosetests. When I used python2 I ran my tests with following command: nosetests --stop --verbose --with-profile --profile-restrict='tests.py' --nocapture tests.py Now I run…
mouse_00
  • 593
  • 3
  • 13
1
vote
2 answers

Maya script won't run in Maya 2022. `reload` is not defined

Trying to run a script that works fine in maya 2018 but wont in 2022 import gw_anim_clip reload(gw_anim_clip) gw_anim_clip.anim_clip_ui() I'm getting this error: Error: name 'reload' is not defined Traceback (most recent call last): File "
1
vote
1 answer

Automatically remove leading u'...' in Python strings

I am working on migrating an old Python code base to Python3. There are many strings which have the "u" prefix. Example u'Umlaut üöö' Is there an automated way to remove the leading "u"? A simple regex is does not work: u'schibu': u' at the end must…
guettli
  • 25,042
  • 81
  • 346
  • 663
1
vote
0 answers

Error running '2to3': CreateProcess error=193, %1 is not a valid Win32 application PyCharm

I am trying to convert a huge amount of Python2 codes into Python3. I read about how to use 2to3 tool and I imported the tool from the PyCharm itself by creating an external tool as the screenshot. For running it I right clicked on the python…
josh smith
  • 11
  • 2