support for python 3 #57

ghost opened this Issue Jul 17, 2012 · 5 comments


None yet
4 participants

ghost commented Jul 17, 2012

Have plans to do a python3 support?.Actually it raises an error for print('anything',end=' ')


kevinw commented Jul 21, 2012

I haven't kept up on how to release a package with both Python 2.x and 3.x support simultaneously. Are there vims being built with Py3 yet?


ghost commented Jul 21, 2012

I do a .vimrc that runs both(pyflakes and pyflakes3k).Is not the best solution but works! I don't use any plugin...only run command in the current file.
An interesting thing in plugin is the quickfix window.I use onle a new tab.

jquast commented Apr 17, 2013

I've gotten a half-baked solution in the works .. not sure of the encoding is done correctly, I think vim may not support various forms of unicode handling with python3. Changes are needed to the sys.exc_info() trapping to work correctly.

It is possible to make the same python code work in either version, but I can't find a way to make the line:
python << EOF
be anamorphic, and do
python3 << EOF
when 'python3' is compiled. So perhaps the code has to be duplicated ??

myint commented Nov 11, 2013

Below are the relevant changes I made to my pyflakes.vim in case anyone has a similar need:

diff --git a/vim/ftplugin/python/pyflakes.vim b/vim/ftplugin/python/pyflakes.vim
index 89f292d..53c774f 100644
--- a/vim/ftplugin/python/pyflakes.vim
+++ b/vim/ftplugin/python/pyflakes.vim
@@ -24,8 +24,8 @@ endif
 if !exists("b:did_python_init")
     let b:did_python_init = 0

-    if !has('python')
-        " the pyflakes.vim plugin requires Vim to be compiled with +python
+    if !has('python3')
+        " the pyflakes.vim plugin requires Vim to be compiled with +python3

@@ -34,7 +34,7 @@ if !exists('g:pyflakes_use_quickfix')

-    python << EOF
+    python3 << EOF
 import vim
 import os.path
 import sys
@@ -72,7 +72,6 @@ def check(buffer):

     # shebang usually found at the top of the file, followed by source code encoding marker.
     # assume everything else that follows is encoded in the encoding.
-    encoding_found = False
     for n, line in enumerate(contents):
         if n >= 2:
@@ -82,10 +81,6 @@ def check(buffer):

     contents = '\n'.join(contents) + '\n'

-    vimenc = vim.eval('&encoding')
-    if vimenc:
-        contents = contents.decode(vimenc)
     builtins = set(['__file__'])
@@ -235,7 +230,7 @@ if !exists("*s:RunPyflakes")
         let b:qf_list = []
         let b:qf_window_count = -1

-        python << EOF
+        python3 << EOF
 for w in check(vim.current.buffer):
     if not isinstance(w.lineno, int):
         lineno = str(w.lineno.lineno)

Erotemic commented Feb 7, 2017

This is a bit old, but I just found a solution for this.

if has('python')
    command! -nargs=1 Python2or3 python <args>
elseif has('python3')
    command! -nargs=1 Python2or3 python3 <args>
    echo "Error: Requires Vim compiled with +python or +python3"

Python2or3 << EOF
import sys
import os
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment