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

Can't run MacVim after installing YCM #18

Closed
beaumartinez opened this issue Feb 5, 2013 · 86 comments · Fixed by #128
Closed

Can't run MacVim after installing YCM #18

beaumartinez opened this issue Feb 5, 2013 · 86 comments · Fixed by #128

Comments

@beaumartinez
Copy link

I installed YCM as per the instructions on the readme, and now MacVim crashes immediately after starting.

Running it in the terminal I get—

Fatal Python error: PyThreadState_Get: no current thread
Vim: Caught deadly signal ABRT
Vim: Finished.

I'm running MacVim 7.3 (snapshot 66) for OS X 10.8 (Mountain Lion), as downloaded from the official Google Code project page.

Running plain old Vim (which IIRC I brew installed), I get—

Vim: Caught deadly signal ABRT
Vim: Finished.
Abort trap: 6

When I ran :BundleInstall Valloric/YouCompleteMe, MacVim didn't crash—but then I'm not sure if it required an reboot to fully "install".

@Hates
Copy link

Hates commented Feb 5, 2013

Currently have the same problem. Followed both the cmake and make procedures which complete fine. Here is my make ycm_core output:

https://gist.github.com/Hates/4715120

@grncdr
Copy link
Contributor

grncdr commented Feb 5, 2013

I'm seeing the same here, using the version of MacVim installed and linked by homebrew

see https://gist.github.com/grncdr/4712845 for the vim -V9 and vim --version output.

EDIT: just saw #8, I still get the same thing with the binary version of MacVim downloaded from http://code.google.com/p/macvim. I've also tried removing all plugins except vundler and YCM from my config, but I still get the same crash.

@vishvananda
Copy link

I also get the same crash with MacVim from homebrew and the binary download. I'm also using python 2.7.3 from homebrew.

@grncdr
Copy link
Contributor

grncdr commented Feb 5, 2013

Ah that's a clue. brew unlink python and it works.

@beaumartinez
Copy link
Author

brew unlink python and it works

So it does. Awesome find. Any insights into how that fixed things, anyone?

Incidentally, I'm not keen on having to use the system's Python—any way we can patch YMC up to make it play nice with homebrew Python?

@vishvananda
Copy link

it looks like vim uses libpython. I suspect we need it to use brew's libpython: /usr/local/Cellar/python/2.7.3/lib/libpython2.7.dylib

@Hates
Copy link

Hates commented Feb 5, 2013

Excellent find @grncdr brew unlink python did the trick for me.

@vishvananda
Copy link

super hacky workaround for downloaded vim:

DYLD_FORCE_FLAT_NAMESPACE=1 DYLD_INSERT_LIBRARIES=/usr/local/Cellar/python/2.7.3/lib/libpython2.7.dylib /Applications/MacVim.app/Contents/MacOS/Vim

I personally have a script called /usr/local/bin/vim that i use to run the brew version:

https://gist.github.com/vishvananda/4717499

@sgrankin
Copy link

sgrankin commented Feb 6, 2013

I've patched my homebrew to make the MacVim build use homebrew's python, as otherwise it picked up the system python library and the homebrew python runtime and caused some strange failures in other python plugins. (https://gist.github.com/sgrankin/4719255 for the formula)

With that, I had the 'no current thread' error after installing YCM. Adding these flags to the cmake command fixed it:
-DPYTHON_INCLUDE_DIR=/usr/local/Frameworks/Python.framework/Headers -DPYTHON_LIBRARY=/usr/local/Frameworks/Python.framework/Python

Everything appears to agree on the python being used after that.

@jtratner
Copy link

jtratner commented Feb 6, 2013

I have this issue too, hope something can be done about it.

Btw - if you have python installed as a framework, then you need to point to a different libpython

DYLD_FORCE_FLAT_NAMESPACE=1 DYLD_INSERT_LIBRARIES=/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib /Applications/MacVim.app/Contents/MacOS/Vim

@grncdr
Copy link
Contributor

grncdr commented Feb 6, 2013

So, even more curious, I removed and reinstalled Homebrew's python, and now everything works fine. Can somebody else confirm?

@jassinm
Copy link

jassinm commented Feb 6, 2013

@sgrankin additional cmake flags helped. Thanks much...

cmake -G "Unix Makefiles" -DPATH_TO_LLVM_ROOT=~/ycm_temp/clang+llvm-3.2-x86_64-apple-darwin11 -DPYTHON_INCLUDE_DIR=/usr/local/Frameworks/Python.framework/Headers -DPYTHON_LIBRARY=/usr/local/Frameworks/Python.framework/Python . ~/.vim/bundle/YouCompleteMe/cpp

I would probably add this to the doc as many python dev's build vim/mvim using homebrew's python

@sgrankin
Copy link

sgrankin commented Feb 6, 2013

@grncdr Installing the new homebrew python did indeed work (after rebuilding both python and macvim), and without the mods or options that I listed. It appear's homebrew 902d22 change fixes the python install so that the include_dir/library are correctly detected.

@Valloric
Copy link
Member

Valloric commented Feb 6, 2013

@sgranking Am I correct in summarizing this thread by saying that the fix is to call brew upgrade python?

@jassinm
Copy link

jassinm commented Feb 6, 2013

I did not upgrade python nor reinstall vim or mvim. I just did pointed cmake to the homebrew framework dirs. (previously install brew install python --framework).

cmake -G "Unix Makefiles" -DPATH_TO_LLVM_ROOT=~/ycm_temp/clang+llvm-3.2-x86_64-apple-darwin11 -DPYTHON_INCLUDE_DIR=/usr/local/Frameworks/Python.framework/Headers -DPYTHON_LIBRARY=/usr/local/Frameworks/Python.framework/Python . ~/.vim/bundle/YouCompleteMe/cpp

@vishvananda
Copy link

I don't use python --framework but after uninstalling python with brew and reinstalling, my next build of macvim used the system pythonlib so it is now working without modification

@sgrankin
Copy link

sgrankin commented Feb 6, 2013

@Valloric More like brew rm python; brew install python as this change happened without changing the version. And then macvim needs to be rebuild as well.

@Valloric
Copy link
Member

Valloric commented Feb 6, 2013

I'm closing this since it's a configuration issue and sadly not something that can be fixed on YCM's side. I've added a new FAQ item for this (that also links to this issue) and noted it in the Mac installation guide.

@xgalaxy
Copy link
Contributor

xgalaxy commented Feb 17, 2013

I think the instructions in the FAQ are insufficient as I just got done going through hell trying to figure out why after installing brewed python vim suddenly started segfaulting and it turns out to be this plugin.

The real fix here is to add the LD flags suggested earlier to the cmake command so that cmake finds the brewed version of python.

Perhaps we can add an additional flag to the install.sh script?
IMO this is a Cmake bug.

For reference, here is what I had to change with the install.sh:

function install {
  ycm_dir=`pwd`
  build_dir=`mktemp -d -t ycm_build.XXXX`
  pushd $build_dir
  cmake -G "Unix Makefiles" -DPYTHON_INCLUDE_DIR=/usr/local/Frameworks/Python.framework/Headers -DPYTHON_LIBRARY=/usr/local/Frameworks/Python.framework/Python $1 . $ycm_dir/cpp
  make ycm_core
  popd
}

@xgalaxy
Copy link
Contributor

xgalaxy commented Feb 17, 2013

Did a little more digging and it appears other brew formula have 'work arounds' in their installation scripts that YouCompleteMe could borrow from:

See:
Homebrew/legacy-homebrew#10393

Of particular interest:
https://github.com/mxcl/homebrew/blob/51d054c/Library/Formula/vtk.rb#L31-49

@pencilcheck
Copy link

http://stackoverflow.com/a/12697440/1742820

Here is a workaround that works for me.

@vaz
Copy link

vaz commented Mar 23, 2013

I think that the FAQ item regarding this is still not as helpful as it could be.

This isn't particular to homebrew in any way. I had python installed as a framework under /Library (from some installer, I forget), which was the python that the ycm_core installer discovered (correctly, due to xgalaxy's python_finder fix). However, my MacVim (which I'd compiled by hand) was using my system python. I fixed this using the symlinking hack (referenced by pencilcheck just above).

Homebrew-MacVim also uses system python (unless the user figures out how to link it against a different one, with the symlinking hack or some other way). This will likely get fixed at some point (either by a workaround in the homebrew formula or better detection by MacVim at compile time). The binary MacVim distribution, of course, always links against system python.

So as it stands, the majority of MacVim users will have a MacVim linked against system python (but some won't). Many users won't have some other python installed (but some will).

I think that it just needs to be made clear that YCM is going to compile against whatever python (and python-config, which should match) it finds in the PATH. Unless there's a way to reliably determine which python is being used by vim (and I haven't been able to figure out a reliable way... sys.version isn't specific enough and sys.executable outright lies sometimes), the user needs to make the call. The advice that would probably fix most people's problems when they're getting a segfault is to try putting their system python first on their PATH when compiling ycm_core.

@jojojames
Copy link

I found the problem here is similar to the problem here.
https://bugs.launchpad.net/ultisnips/+bug/1156584

SirVer's solution of changing the python worked for me.

@noscripter
Copy link

This problem annoys me for days and I finally came to a solution as below:

  1. brew rm python; // remove brew installed python completely, but if you really have to use that, act with caution.
  2. brew rm macvim; // remove installed macvim first to prepare for new installation.
  3. brew install macvim --with-python; // new installation of macvim with the support of python
  4. Either repeat your installation with YouCompleteMe, or if you have already installed and compiled it, you can just enjoy it(this is exactly my case).

Hope somebody find this useful.

@jmarrama
Copy link

@noscripter your general solution worked for me, i also had to do a brew rm vim; brew install vim --with-python, and then recompile YouCompleteMe linking to the new python installed in steps 1 and 2. Thanks!

@nfx
Copy link

nfx commented Apr 30, 2015

For homebrew it should actually be something like

env PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin/ bash install.sh

which uses default homebrew linked thing.

@noscripter
Copy link

@fasiha
Copy link

fasiha commented May 29, 2015

@imkira's suggestion (to edit YouCompleteMe/third_party/ycmd/cpp/ycm/CMakeLists.txt to insist on Python >=2.7) was half of my fix. Specifically, after this fix, the YouCompleteMe build happily reported, near the top, that it was finally using brew's Python:

-- Found PythonLibs: /usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib (found suitable version "2.7.10", minimum required is "2.7") 
-- Found PythonInterp: /usr/local/bin/python2.7 (found suitable version "2.7.10", minimum required is "2.7") 

Note that /usr/local/bin/python2.7 is symlinked to brew's python in /usr/local/Cellar… Before this CmakeLists.txt edit, install.sh was reporting different PythonLibs and PythonInterp:

-- Found PythonLibs: /usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib (found suitable version "2.7.10", minimum required is "2.6") 
-- Found PythonInterp: /usr/bin/python2.6 (found suitable version "2.6.8", minimum required is "2.6") 

Once these two matched, I thought I was home free. But MacVim was still crashing with ABRT!

The other half involved forcing MacVim, which I was building from source per the YCM docs, to use brew's Python. Turns out it was built using system python: remove YouCompleteMe/ from ~/.vim/bundle to avoid ABRT crash and invoking :python print(sys.version) reported using an older python, which told me it was non-brew. In MacVim, ./configure --enable-pythoninterp was still reporting

checking Python's install prefix... (cached) /System/Library/Frameworks/Python.framework/Versions/2.7
checking Python's execution prefix... (cached) /System/Library/Frameworks/Python.framework/Versions/2.7
(cached) checking Python's configuration directory... (cached) /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config

The "(cached)" seemed a problem so I deleted MacVim/src/auto/config.cache and upon re-running ./configure --enable-pythoninterp, configure found brew's python.

(If MacVim's configure was still finding system python, I'd have tried the solutions on SO to get MacVim to find the right Python. But it looks like brew remove python && brew update && brew install python, plus deleting MacVim's configure cache, was sufficient.)

Moved YouCompleteMe back into ~/.vim/bundle and all is well 😂!

(This was all on Mavericks. Interestingly, I also installed MacVim from github and YCM on a fresh clean Yosemite this morning and didn't run into any of this… lucky.)

@levbrie
Copy link

levbrie commented Jun 23, 2015

Following @imkira's suggestion as well as @fasiha's I almost got everything working, but in the end the only thing that solved it for me was finally taking @Valloric's advice in the README and installing MacVim directly, rather than using homebrew or trying to work with another version of vim. If you're having this problem and did not build MacVim yourself, I highly recommend you try this first.

@jmeridth
Copy link

jmeridth commented Jul 3, 2015

This worked for me. Hope it helps someone else.

NOTE:
/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/Current

the 2.7.10 portion needs to be the latest version you have installed with Homebrew

brew rm -f python
brew rm -f macvim
brew install python
brew linkapps python
brew install macvim --with-python --with-override-system-vim
brew linkapps macvim
cd ~/.vim/bundle/YouCompleteMe
./install.py --clang-completer

Update: 8/4/2015
I just used this again after upgrading python on my mac and it worked. 😄

@daniel0076
Copy link

@harciga solution works for me
however, I have to select python27-apple for it to run

@junwei-wang
Copy link

@jmeridth Also works for me...

@ActionScripted
Copy link

Another way to get things working, taking a page from the OS X install in YCM's readme:

brew cask uninstall --force macvim
brew uninstall -f vim
brew unlink python
brew cask install macvim
cd /usr/local/bin/
ln -s mvim vim
cd ~/.vim/bundle/YouCompleteMe
./install.py --clang-completer

Now everything should work as expected and you didn't have to mess with system Python.

@jalexvig
Copy link

+1 @rfurman

@lorry-lee
Copy link

I resolved by removing redundant python. For me seems it's because if my OSX has different version of python installed, from System, from homebrew, from Xcode etc.

So use:

type -a python

to see where are those python installed and remove them. Seems I can't remove the one come with the system:

/usr/bin/python

so I kept that one and remove all others like:

cd /Library/Frameworks/
mv Python.framework x

Then go to Ycm and run:

./install.sh

to recompile and install ycm.

Then it works for me.

@diffractometer
Copy link

@ActionScripted nice, that worked for me.

@puremourning
Copy link
Member

For the record:

I have found that if using pyenv to install python and you get the infamous

Fatal Python error: PyThreadState_Get: no current thread

Then you must add the --enable-shared flag manually:

PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 2.7.10

@puremourning
Copy link
Member

Correction. That works for python 3.5, but it looks like pyenv can't build --enable-shared on some versions (like 3.3.6). Better to try:

PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 2.7.10

@hackrole
Copy link

I face the same error. cause I have three python 2.7 install. one system. one download from the python.org, one install from brew. I fixed it with the following. hope may help others.

# rm python.org python
# have a look at this:  http://stackoverflow.com/questions/3819449/how-to-uninstall-python-2-7-on-a-mac-os-x-10-6-4

# reinstall python and macvim
brew rm python
brew install python
brew rm macvim
brew install macvim

# rebuild YCM
cd .vim/bundle/YouCompleteme
./install.py

now it works.

@cbioley
Copy link

cbioley commented Feb 24, 2016

@hackrole Ha! Thank you!

@nicohvi
Copy link

nicohvi commented Feb 25, 2016

@hackrole's solution also worked for me, thank you very much 👍

@freeX1n
Copy link

freeX1n commented Nov 11, 2016

Recently I install a python 2.7.12 apart from the system one 2.7.10 and face the same error. But maybe because I did not install the macvim by homebrew before, below works for me.

-- No uninstalling python and macvim.
-- Just install macvim
brew install macvim

-- rebuild YCM
cd .vim/bundle/YouCompleteme
./install.py

I think it may be not necessary to reinstall the homebrew's python because this error is only related to the python configuration in MacVim and YouCompleteMe. And if you have a homebrew's python, when it is about to build the MacVim, it should know to configure it with the homebrew's one. The same as the YouCompleteMe.

Anyway, thanks all and especially to @hackrole .

@Nicozheng
Copy link

Just figure it out, it's mainly because the _io.so file is different in python 2.6 / 2.7.5 / 2.7.13, so if you still want to use the homebrew version python in terminal using "python", you should copy the old version io.so file into the 2.7.13 directory.

First, run the following code in terminal

sudo find / -name _io.so

Here is mine:
/Applications/Google Drive.app/Contents/Resources/lib/python2.7/lib-dynload/_io.so
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
/Users/Nico/macports/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so

Second, copy the 2.7.13 version io file to backup

cd Desktop
mkdir backup_python
cp /usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so backup_python/2.7.13_io.so

Third, copy the old version to replace the new one

cp /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so /usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so

Then it will be all set!

@Jonathan0wh
Copy link

Thanks samueljon, changing to python 3 by add python flag:

--enable-python3interp vi_cv_path_python3=/usr/local/bin/python3
--enable-pythoninterp

by editing "brew edit macvim" works for me

@umang94
Copy link

umang94 commented Sep 20, 2017

uninstalling brew installed python2.X worked for me.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.