Reputation: 3862
I'm trying to run a python (version 3.6.2) program that also uses the "gi" module. When I try to import the "gi", it gives me the error below:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/gi/__init__.py", line 39
print url
^
SyntaxError: Missing parentheses in call to 'print'
The only thing that I do is to import it.
import gi
Upvotes: 2
Views: 1294
Reputation: 16214
You can use the tool 2to3 is an Automated Python 2 to 3 code translation, you can get over a ride throw the old python and making the changes work into python 3, I make a simple example like this:
I created this file, python2.py:
#!python3
print 5
when I run it with python it obviously shows:
line 3
print 5 ^
SyntaxError: Missing parentheses in call to 'print'
so, you can transform it via terminal like this:
This is the important comand
$ 2to3 -w home/path_to_file/python2.py
-w parameter will write the file, if you want only see the future changes without apply them, just run it without -w. after run it it will show something like
root: Generating grammar tables from /usr/lib/python2.7/lib2to3/PatternGrammar.txt
RefactoringTool: Refactored Desktop/stackoverflow/goto.py
--- Desktop/stackoverflow/goto.py (original)
+++ Desktop/stackoverflow/goto.py (refactored)
@@ -1,3 +1,3 @@
#!python3
-print 5
+print(5)
RefactoringTool: Files that were modified:
And the file will look like:
#!python3
print(5)
Upvotes: 1