Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name MAXREPEAT when launching MacVim #241

Closed
dustMason opened this issue Apr 10, 2013 · 15 comments
Closed

ImportError: cannot import name MAXREPEAT when launching MacVim #241

dustMason opened this issue Apr 10, 2013 · 15 comments

Comments

@dustMason
Copy link

I'm running the latest YCM, installed via pathogen along with brew macvim and python (also up to date as of today). I rebuilt ycm_core and verified that all bins are linked as they should be. Otherwise vim and python are working fine.

I checked out Issue #18 but none of the suggestions there seemed to solve my issue. Until about a week ago I was using YCM without any issues although I don't know what could have changed since then.

Thanks!

Here is the terminal output from mvim .

Traceback (most recent call last):
  File "/usr/local/Cellar/python/2.7.4/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 563, in <module>
    main()
  File "/usr/local/Cellar/python/2.7.4/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 545, in main
    known_paths = addusersitepackages(known_paths)
  File "/usr/local/Cellar/python/2.7.4/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 278, in addusersitepackages
    user_site = getusersitepackages()
  File "/usr/local/Cellar/python/2.7.4/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 253, in getusersitepackages
    user_base = getuserbase() # this will also set USER_BASE
  File "/usr/local/Cellar/python/2.7.4/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 243, in getuserbase
    USER_BASE = get_config_var('userbase')
  File "/usr/local/Cellar/python/2.7.4/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sysconfig.py", line 472, in get_config_var
    return get_config_vars().get(name)
  File "/usr/local/Cellar/python/2.7.4/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sysconfig.py", line 405, in get_config_vars
    import re
  File "/usr/local/Cellar/python/2.7.4/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 105, in <module>
    import sre_compile
  File "/usr/local/Cellar/python/2.7.4/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sre_compile.py", line 14, in <module>
    import sre_parse
  File "/usr/local/Cellar/python/2.7.4/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sre_parse.py", line 17, in <module>
    from sre_constants import *
  File "/usr/local/Cellar/python/2.7.4/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sre_constants.py", line 18, in <module>
    from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT
@Valloric
Copy link
Member

This seems like an issue with your system configuration. I can't really help there (wouldn't know how to).

@skryl
Copy link

skryl commented Apr 16, 2013

Your MacVim binaries are linked against your system python instead of homebrew's. You can double check using otool.

otool -L /usr/local/Cellar/macvim/7.3-66/MacVim.app/Contents/MacOS/MacVim

If you see the /System/.../Python.framework in there then that's your issue.

You can relink the binary against homebrew's version of the framework without recompiling...

cd /usr/local/Cellar/macvim/7.3-66/MacVim.app/Contents/MacOS/

install_name_tool -change /System/Library/Frameworks/Python.framework/Versions/2.7/Python /usr/local/Cellar/python/2.7.4/Frameworks/Python.framework/Versions/2.7/Python MacVim

install_name_tool -change /System/Library/Frameworks/Python.framework/Versions/2.7/Python /usr/local/Cellar/python/2.7.4/Frameworks/Python.framework/Versions/2.7/Python Vim

@dustMason
Copy link
Author

Thanks @skryl. You're totally correct and this is basically how I ended up solving the problem.

@zen
Copy link

zen commented May 6, 2013

I have exact same issue and my MacVim is not linked against system python. Any suggestions how to fix that?

@xuhdev
Copy link

xuhdev commented May 7, 2013

@zen I also have this issue. You can do what the comments suggested above, but I think there should be a more elegant way.

@jordanthornquest
Copy link

Hey, folks. I am having this same issue with plain-ol Terminal Vim. Any suggestions?

@jordanthornquest
Copy link

Whoops! Nevermind, I got it! Thanks, @skryl: your answer helped immensely.

@ricardodani
Copy link

Hi, I have this issue too, but in my case i don`t have a /System/.../Python.framework in the "otool -L /usr/local/Cellar/macvim/7.3-66/MacVim.app/Contents/MacOS/MacVim" output.

So, i believe it`s not a -change command in my case. Any suggestions?

Thanks

@unphased
Copy link

I too was able to finally get YCM going on OS X, thanks @skryl

Maybe this info will help others in a similar situation to where I was.

Here is the output of properly linked vim:

lust@Stevens-MacBook-Pro:~/vim 2:51:49
❯ otool -L ~/vim/src/vim
/Users/lust/vim/src/vim:
    /usr/local/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
    /usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
    /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
    /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 19.0.0)
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/libruby.1.dylib (compatibility version 1.8.0, current version 1.8.7)
    /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
    /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 744.18.0)
    /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 57.0.0)
    /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1187.37.0)
    /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 945.16.0)

where

lust@Stevens-MacBook-Pro:~/vim 2:54:49
❯ ls -la /usr/local/Frameworks/
total 8
drwxr-xr-x   3 lust  admin  102 May 10 02:11 .
drwxrwxr-x  17 root  admin  578 May 10 02:11 ..
lrwxr-xr-x   1 lust  admin   50 May 10 02:11 Python.framework -> ../Cellar/python/2.7.4/Frameworks/Python.framework

Here is my original bad vim which had horrible python issues

lust@Stevens-MacBook-Pro:~/.vim/bundle 2:09:27
❯ otool -L ~/vim/src/vim
/Users/lust/vim/src/vim:
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
    /usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
    /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
    /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 19.0.0)
    /System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.2)
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/libruby.1.dylib (compatibility version 1.8.0, current version 1.8.7)
    /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
    /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 744.18.0)
    /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 57.0.0)
    /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1187.37.0)
    /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 945.16.0)

The vim makefile does detect brew's python and in fact uses it for headers, but then goes and links with -framework Python, which brew has NOT by default pointed towards brew's python lib. So that's the discrepancy. Dunno whose fault it is, brew project, python project, or vim project.

@von
Copy link

von commented May 11, 2013

Just a note for anyone, like me, who runs into this issue (ImportError: cannot import name MAXREPEAT) after installing UltiSnips, the problem and solution are the same: https://bugs.launchpad.net/ultisnips/+bug/1178439

@nhstanley
Copy link

I, too, was having this issue, as well as the segfault/abort issue with YCM upon vim startup. I will explain my fixes for both here, since dealing with two sources of problems is much harder than either one alone. Maybe this is obvious for everyone else, but it took me a while to figure out what was going wrong.

I had installed Python, Vim, and MacVim with Homebrew. I then installed YCM with Vundle. I ran into the segfault issue (#18). To solve it, I uninstalled YCM and reinstalled, but this time forcing YCM to link to homebrew python. I had to modify ~/.vim/bundle/YouCompleteMe/install.sh a little to force the correct python path upon compile:

...
function python_finder {
  #python_library="-DPYTHON_LIBRARY="
  #python_include="-DPYTHON_INCLUDE_DIR="
  python_library="-DPYTHON_LIBRARY=/usr/local/Frameworks/Python.framework/Python"
  python_include="-DPYTHON_INCLUDE_DIR=/usr/local/Frameworks/Python.framework/Headers"

  ...

  echo "${python_library} ${python_include}"
}
...

After this, regular Vim worked fine, but MacVim crashed with the MAXREPEAT error. To fix that, I also had to force MacVim to use the correct, homebrew python:

cd /usr/local/Cellar/macvim/7.3-66/MacVim.app/Contents/MacOS/
install_name_tool -change /System/Library/Frameworks/Python.framework/Versions/2.7/Python /usr/local/Cellar/python/2.7.4/Frameworks/Python.framework/Python Vim

Something similar would work for non-Homebrew MacVim, I assume. In general, it will also simplify your life if you make sure the python in your shell path is the homebrew python.

@gavinbeatty
Copy link

For me, the solution was to add a framework search path using LDFLAGS=-F/opt/local/Library/Frameworks

@nathania
Copy link

Ran into this error after installing YCM via pathogen; I'm running MacPorts MacVim, cmake, and Python.

The issue was resolved on my machine by (1) modifying install.sh as shown below, and (2) activating a variant of MacVim compiled without +python33. Note that I extracted the llvm archive file to ~/ycm_temp/llvm (cf. step 3 of the YCM installation instructions).

function python_finder {
   python_library="-DPYTHON_LIBRARY=/opt/local/Library/Frameworks/Python.framework/Python"
   python_include="-DPYTHON_INCLUDE_DIR=/opt/local/Library/Frameworks/Python.framework/Headers"
   echo "${python_library} ${python_include}"
} 
...
for flag in $@; do
   case "$flag" in
     --clang-completer)
     cmake_args="-DPATH_TO_LLVM_ROOT=~/ycm_temp/llvm"
     ;;
...

@burnettk
Copy link

burnettk commented Apr 2, 2014

Here's the hammer I employed (I had an older version of python) to resolve this issue:

brew update && brew uninstall python vim macvim --force && brew install python macvim --with-lua && brew linkapps
alias vim='mvim -v' # don't need the vim package

@yqrashawn
Copy link

#881

Von's method under this issue fixed it.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests