Python-mode: Errors when opening up any .py files

Created on 27 Sep 2020  路  3Comments  路  Source: python-mode/python-mode

I've installed python-mode on a WSL Ubuntu 18.04 subsystem (Windows 10) and get the following error whenever I open any *.py file.

Error detected while processing BufRead Autocommands for "*.py"..FileType Autocommands for "*"..function <SNR>6_LoadFTPlugin[17]..script /home/user/.vim/bundle/python-mode/ftplugin/python/pymode.vim[21]..function pymode#init:
line    2:
E121: Undefined variable: import
line    3:
E121: Undefined variable: sys
line    4:
E121: Undefined variable: sys
Error detected while processing BufRead Autocommands for "*.py"..FileType Autocommands for "*"..function <SNR>6_LoadFTPlugin[17]..script /home/user/.vim/bundle/python-mode/ftplugin/python/pymode.vim[22]../home/user/.vim/bundle/python-mode/autoload/pymode/virtualenv.vim:
line    3:
E121: Undefined variable: from
Error detected while processing BufRead Autocommands for "*.py"..FileType Autocommands for "*"..function <SNR>6_LoadFTPlugin[17]..script /home/user/.vim/bundle/python-mode/ftplugin/python/pymode.vim[23]..function pymode#breakpoint#init:
line    9:
E15: Invalid expression: << EOF
line   11:
E492: Not an editor command: from importlib.util import find_spec
line   13:
E121: Undefined variable: sys
line   16:
E488: Trailing characters: :: else:
line   23:
E170: Missing :endfor

However, when I hit enter, the file opens up, seemingly as per normal.

I tried looking through #915 and #972 but couldn't find an answer there. Would greatly appreciate any advice

I cleared the cache:

find <path_to_pymode> -type f -iname '*.pyc' -o -iname '*.pyo' -delete && find . -type d -name '__pycache__' -delete

and ran the following on the python file test.py which simply had print("Hello World") inside.:

vim -i NONE -u <path_to_pymode>/debugvimrc.vim test.py

1601215636 let g:pymode_virtualenv_enabled = "/home/user/.virtualenvs/stock-analytics" []
-------------------------------------------------------------------------------
pymode debug msg 1: Starting debug on: 2020-09-27 15:07:16 with file /tmp/pymode_debug_file.txt
-------------------------------------------------------------------------------
pymode debug msg 2: Operating system: Linux
-------------------------------------------------------------------------------
pymode debug msg 3: Scriptnames:
-------------------------------------------------------------------------------
pymode debug msg 4: Pymode variables:
pymode                #1
pymode_breakpoint     #1
pymode_breakpoint_bind  <leader>b
pymode_breakpoint_cmd  import pdb; pdb.set_trace()  # XXX BREAKPOINT
pymode_debug          #1
pymode_debug_counter  #3
pymode_debug_tempfile  /tmp/pymode_debug_file.txt
pymode_doc            #1
pymode_doc_bind        K
pymode_doc_vertical   #0
pymode_folding        #0
pymode_folding_nest_limit #1000
pymode_folding_regex   ^\s*\%(class\|def\|async\s\+def\) .\+\(:\s\+\w\)\@!
pymode_indent         #1
pymode_init           #1
pymode_lint           #1
pymode_lint_async     #1
pymode_lint_async_updatetime #1000
pymode_lint_checkers  ['pyflakes', 'pep8', 'mccabe']
pymode_lint_comment_symbol  CC
pymode_lint_cwindow   #1
pymode_lint_docs_symbol  DD
pymode_lint_error_symbol  EE
pymode_lint_ignore    []
pymode_lint_info_symbol  II
pymode_lint_message   #1
  mode_lint_on_fly    #0
           _on_write  #1
pymode_lint_options_mccabe {'complexity': 12}
pymode_lint_options_pep257 {}
pymode_lint_options_pep8 {'max_line_length': 79}
pymode_lint_options_pyflakes {'builtins': '_'}
pymode_lint_options_pylint {'max-line-length': 79}
pymode_lint_pyflakes_symbol  FF
pymode_lint_select    []
pymode_lint_signs     #1
pymode_lint_sort      []
pymode_lint_todo_symbol  WW
pymode_lint_unmodified #0
pymode_lint_visual_symbol  RR
pymode_motion         #1
pymode_options        #1
pymode_options_colorcolumn #1
pymode_options_max_line_length #79
pymode_paths          []
pymode_preview_height #12
pymode_preview_position  botright
pymode_python          python3
pymode_quickfix_maxheight #6
pymode_quickfix_minheight #3
pymode_rope           #0
pymode_run            #1
pymode_run_bind        <leader>r
pymode_trim_whitespaces #1
pymode_version         0.11.0
pymode_virtualenv     #1
pymode_virtualenv_enabled  /home/user/.virtualenvs/stock-analytics
pymode_virtualenv_path  /home/user/.virtualenvs/stock-analytics
pymode_warning        #1
-------------------------------------------------------------------------------
pymode debug msg 5: Git commit:
295e84d9dd7f4887f8a5635e9dfe88dfeabaf00c
-------------------------------------------------------------------------------
pymode debug msg 6: Git submodule status:
 a672051f4406da0beb01e88767e8e46488eb71eb submodules/astroid (a672051)

Versions and Installations

I installed python-mode using Vundle, and tried using Plugin 'python-mode/python-mode' and Plugin 'klen/python-mode'. Both methods yielded the same problem. I also tried installing it using the git clone --recurse-submodules https://github.com/python-mode/python-mode -c core.symlinks=true (for a Windows OS) but the problem persists.

vim --version:

VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Sep 27 2020 02:56:34)
Included patches: 1-1751
Compiled by user@pc
Huge version without GUI.  Features included (+) or not (-):
+acl               -farsi             +mouse_sgr         +tag_binary
+arabic            +file_in_path      -mouse_sysmouse    -tag_old_static
+autocmd           +find_in_path      +mouse_urxvt       -tag_any_white
+autochdir         +float             +mouse_xterm       -tcl
-autoservername    +folding           +multi_byte        +termguicolors
-balloon_eval      -footer            +multi_lang        +terminal
+balloon_eval_term +fork()            -mzscheme          +terminfo
-browse            +gettext           +netbeans_intg     +termresponse
++builtin_terms    -hangul_input      +num64             +textobjects
+byte_offset       +iconv             +packages          +textprop
+channel           +insert_expand     +path_extra        +timers
+cindent           +ipv6              -perl              +title
-clientserver      +job               +persistent_undo   -toolbar
-clipboard         +jumplist          +popupwin          +user_commands
+cmdline_compl     +keymap            +postscript        +vartabs
+cmdline_hist      +lambda            +printer           +vertsplit
+cmdline_info      +langmap           +profile           +virtualedit
+comments          +libcall           -python            +visual
+conceal           +linebreak         +python3           +visualextra
+cryptv            +lispindent        +quickfix          +viminfo
+cscope            +listcmds          +reltime           +vreplace
+cursorbind        +localmap          +rightleft         +wildignore
+cursorshape       -lua               -ruby              +wildmenu
+dialog_con        +menu              +scrollbind        +windows
+diff              +mksession         +signs             +writebackup
+digraphs          +modify_fname      +smartindent       -X11
-dnd               +mouse             +sound             -xfontset
-ebcdic            -mouseshape        +spell             -xim
+emacs_tags        +mouse_dec         +startuptime       -xpm
+eval              -mouse_gpm         +statusline        -xsmp
+ex_extra          -mouse_jsbterm     -sun_workshop      -xterm_clipboard
+extra_search      +mouse_netterm     +syntax            -xterm_save
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/share/vim"
 f-b for $VIMRUNTIME: "/usr/share/vim/vim82"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H     -g -O2 -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc   -L/usr/local/lib -Wl,--as-needed -o vim    -lSM -lICE    -lm -ltinfo  -lselinux  -lcanberra -ldl     -L/usr/lib/python3.6/config-3.6m-x86_64-linux-gnu -lpython3.6m -lpthread -ldl -lutil -lm

Python version:

Python 3.6.9

Running :PymodePython import sys; print(sys.version_info) gives the following error: E121: Undefined variable: import which is akin to the error I get when opening .py files.

Most helpful comment

Thanks @lieryan and @diraol, it was indeed an issue with the g:pymode_python setting in the .vimrc. I changed it from

...
175 let g:pymode_python='python'
176 let g:syntastic_python_python_exec='python'
...

to

...
175 let g:pymode_python='python3'
176 let g:syntastic_python_python_exec='python3'
...

and now the installation works without a hitch! Much appreciated.

All 3 comments

Seems like you are hitting the else-branch of this part of the plugin, which might happen if you disabled python features in your .vimrc by setting g:pymode_python to some unrecognized value:

https://github.com/python-mode/python-mode/blob/295e84d9dd7f4887f8a5635e9dfe88dfeabaf00c/plugin/pymode.vim#L296-L312

or autodetection failed on this:

https://github.com/python-mode/python-mode/blob/295e84d9dd7f4887f8a5635e9dfe88dfeabaf00c/plugin/pymode.vim#L21-L26

Can you share your .vimrc file with us, please?

Thanks @lieryan and @diraol, it was indeed an issue with the g:pymode_python setting in the .vimrc. I changed it from

...
175 let g:pymode_python='python'
176 let g:syntastic_python_python_exec='python'
...

to

...
175 let g:pymode_python='python3'
176 let g:syntastic_python_python_exec='python3'
...

and now the installation works without a hitch! Much appreciated.

Was this page helpful?
0 / 5 - 0 ratings