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

macos, qtpy.PythonQtError: No Qt bindings could be found #636

Closed
johnykov opened this Issue Dec 29, 2016 · 18 comments

Comments

Projects
None yet
3 participants
@johnykov

johnykov commented Dec 29, 2016

Hi, brew upgraded my git cola and it stopped working :( please help
My python version is Python 2.7.13
I see

Traceback (most recent call last):
  File "/usr/local/Cellar/git-cola/2.9.1_1/share/git-cola/lib/qtpy/__init__.py", line 119, in <module>
    from PySide import __version__ as PYSIDE_VERSION  # analysis:ignore
ModuleNotFoundError: No module named 'PySide'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/git-cola", line 54, in <module>
    from cola.main import main
  File "/usr/local/Cellar/git-cola/2.9.1_1/share/git-cola/lib/cola/main.py", line 9, in <module>
    from .app import add_common_arguments
  File "/usr/local/Cellar/git-cola/2.9.1_1/share/git-cola/lib/cola/app.py", line 14, in <module>
    from qtpy import QtCore
  File "/usr/local/Cellar/git-cola/2.9.1_1/share/git-cola/lib/qtpy/__init__.py", line 125, in <module>
    raise PythonQtError('No Qt bindings could be found')
qtpy.PythonQtError: No Qt bindings could be found
@davvid

This comment has been minimized.

Member

davvid commented Dec 29, 2016

Check the caveats for pyqt and make sure it's installed. It may be that you have to install homebrew's modules in python's sys.path (see the brew caveats for that formula)

Let me know if that's related or not.

@davvid davvid closed this in 4376546 Dec 29, 2016

@davvid

This comment has been minimized.

Member

davvid commented Dec 29, 2016

Sorry 'bout that. Previously, git-cola was taking care of the sys.path setup on the user's behalf, but that was hurting macports users, so we now require users to follow the steps listed in brew info pyqt.

I added this to the README in the macosx section in an easy to copy/paste section. I just tested this an indeed I was getting the import error until I ran the caveats. Thanks for the heads-up.

@johnykov

This comment has been minimized.

johnykov commented Dec 30, 2016

I see only

==> Caveats
Phonon support is broken.

and no instructions, so it seems not to be related

@johnykov

This comment has been minimized.

johnykov commented Dec 30, 2016

I did https://github.com/git-cola/git-cola#mac-os-x and it didn't help, still same error :(

@davvid

This comment has been minimized.

Member

davvid commented Jan 1, 2017

I'm on el capitan. I hadn't updated brew in a long time. What do these commands print?

python -c 'import PyQt4.QtGui'
python3 -c 'import PyQt5.QtGui'

I think on newer-ish (el-cap+) versions we use python3 + PyQt5, so the PyQt5 line is the one we probably care about.

I seem to have been using PyQt4 because I have that installed from an older version. I updated, unlinked my old install, and then re-installed:

brew update
brew unlink git-cola
brew install git-cola
# if you don't have qt installed this next step can be skipped
brew unlink qt
brew link qt5
# for some reason, I had to do this manually?
brew install pyqt5

... and then it started downloading and installing a bunch fo stuff. Let me know if these steps help.

One thing I just noticed is that the styling seems to be ugly/messed up on PyQt5 on macos. It worked fine with PyQt4. If you're running from the source tree you'll need to use python3 to launch it: python3 ./bin/git-cola

@davvid davvid reopened this Jan 1, 2017

davvid added a commit that referenced this issue Jan 1, 2017

README: revise installation instructions for Mac OS X
Newer versions of Homebrew use Python3 and PyQt5.
Update the instructions for the new Python3-based Homebrew.

Related-to: #636
Signed-off-by: David Aguilar <davvid@gmail.com>
@davvid

This comment has been minimized.

Member

davvid commented Jan 1, 2017

I updated the instructions (again). Modern Homebrew uses Python3, so that required us to change the installation recipe.

The homebrew.pth file in your home directory is no longer needed because homebrew provides their own python. Let me know if stuff works for you after following the updated instructions. I don't know if it's just me, but I had to manually brew install pyqt5 so maybe that's related.

I fixed some minor Mac OS X + PyQt5 styling issues in the master branch so you might want to use that version until the next release.

@johnykov

This comment has been minimized.

johnykov commented Jan 2, 2017

I second case I see:

$ python3 -c 'import PyQt5.QtGui'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'sip'
@johnykov

This comment has been minimized.

johnykov commented Jan 2, 2017

I have:

$ brew install git-cola
Warning: git-cola-2.9.1_1 already installed, it's just not linked.

and

$ brew install pyqt5
Warning: pyqt5-5.7_1 already installed

and still doesn't work :(
same error message
I'm on macOS sierra

@davvid

This comment has been minimized.

Member

davvid commented Jan 2, 2017

Hmm that's puzzling. You're indeed using brew's python3, yeah? which python3 should mention /usr/local/bin/python3 by default for homebrew.

The error message says we're missing the sip module. Does brew install sip also claim it's already installed?

python3 -c 'import sip' should fail if it's not installed, and be silent if the module is available. I'll try upgrading to sierra soon and see if I can reproduce this problem there.

Do you know if you installed stuff and then upgraded to sierra afterwards? It's kinda surprising that homebrew would get into this broken state since it should have already installed sip if you have pyqt5 modules.

What's doubly puzzling is that the PyQt5 modules are available, but the sip ones are missing. The error message did not mention being unable to import PyQt5 -- it mentioned sip.

I don't know if it's an option, but uninstalling homebrew completely and reinstalling it afresh will very likely solve all of these problems.

@johnykov

This comment has been minimized.

johnykov commented Jan 2, 2017

it might be some pyton 2 / python 3 case?

will reinstalling homebrew delete all my software tracked versions?

@johnykov

This comment has been minimized.

johnykov commented Jan 2, 2017

I see:

$ python3 -c 'import sip'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'sip'

and

$ brew install sip
Warning: sip-4.18.1 already installed
@davvid

This comment has been minimized.

Member

davvid commented Jan 2, 2017

Before we do something drastic, how about we just uninstall/reinstall stuff to get python in shape.

If you installed it a while ago, it's possible that these modules were installed for python2, and then upgrading to sierra changed stuff and now homebrew wants python3. So let's try that...

brew uninstall pyqt5
brew uninstall sip
brew uninstall qt5
brew install qt5
brew install sip
brew install pyqt5

Does running the uninstall + re-install get the modules properly installed for python3? Another approach is to use brew install --force but I figured it'd be better to avoid --force by doing an uninstall first.

@johnykov

This comment has been minimized.

johnykov commented Jan 2, 2017

re-install helped, except all of above I see I've got also pyqt 4.11.4. So maybe that was a problem, thanks

@johnykov johnykov closed this Jan 2, 2017

davvid added a commit that referenced this issue Jan 3, 2017

README.md: add instructions detailing how to upgrade using homebrew
Related-to: #636
Signed-off-by: David Aguilar <davvid@gmail.com>
@cfrancois7

This comment has been minimized.

cfrancois7 commented Jan 15, 2018

I get same problem by following the new instructions.
If I lunch git-cola with the command $ python3 ./bin/git-cola in the source repo, everything is fine.
But when I use directly $ git-cola or I want to use the shortcut git-cola.app making from sources, i got this error message:

$ git-cola
Traceback (most recent call last):
  File "/usr/local/Cellar/git-cola/3.0_1/share/git-cola/lib/qtpy/__init__.py", line 119, in <module>
    from PySide import __version__ as PYSIDE_VERSION  # analysis:ignore
ModuleNotFoundError: No module named 'PySide'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/git-cola", line 53, in <module>
    from cola.main import main  # pylint: disable=wrong-import-position
  File "/usr/local/Cellar/git-cola/3.0_1/share/git-cola/lib/cola/main.py", line 7, in <module>
    from .app import add_common_arguments
  File "/usr/local/Cellar/git-cola/3.0_1/share/git-cola/lib/cola/app.py", line 14, in <module>
    from qtpy import QtCore
  File "/usr/local/Cellar/git-cola/3.0_1/share/git-cola/lib/qtpy/__init__.py", line 125, in <module>
    raise PythonQtError('No Qt bindings could be found')
qtpy.PythonQtError: No Qt bindings could be found

Pyqt and sip are already installed with brew.
Maybe it is related to anaconda, but pyqt and pyside are already installed with conda.

@davvid

This comment has been minimized.

Member

davvid commented Jan 17, 2018

The issue above when running out of the source tree is that pyqt/pyside is installed for python3 only. This is expected in homebrew, which ships its own python3 instead of using the system python.

If you're able to to build your own python2 PyQt5 using the system python and homebrew Qt5 that would work, but that's a lot of effort.

This easiest way to make it work out of the source tree in your setup is to edit the #! line in bin/git-cola and bin/git-dag to use python3. Make the very first #!/usr/bin/env python line say #!/usr/bin/env python3 instead.

@cfrancois7

This comment has been minimized.

cfrancois7 commented Jan 19, 2018

In my case, when I build the .app, it was the python from brew that was used and not the python from my system — that is the anaconda's one. The problem is the python from brew cannot import pyside or pyqt while brew says me there're already installed.
I'm looking for to understand this point.

@cfrancois7

This comment has been minimized.

cfrancois7 commented Feb 12, 2018

I struggled to install the git-cola's dependencies with the system's python3 (from brew). When I tried to install pyside through pip with the brew's python3 there were many problems.
I preferred to switch from the brew's python3 to the anaconda python3 I ordinary use.

If you have several python3 installed on your computer, you can define the path of your python bin in the next files:
/Applications/git-cola.app/Contents/MacOs/git-cola
/Applications/git-cola/Resources/bin/git-cola

However, there was still a problem in /Applications/git-cola.app/Contents/MacOs/git-cola when I tried to open the .app with Finder.
The exec "$python" "$contents/Resources/bin/git-cola" --prompt leads to an error in my case (open and crash immediately).
Why not just exec "$contents/Resources/bin/git-cola" --prompt? It works fine for me.

I don't really understand the variable "python" here:

# $0 = Contents/MacOS/git-cola
macos="$(dirname "$0")"
contents="$(dirname "$macos")"
python="$contents/Resources/git-cola"

if ! test -e "$python"
then
	python=python
fi

exec "$python" "$contents/Resources/bin/git-cola" --prompt
@davvid

This comment has been minimized.

Member

davvid commented Mar 17, 2018

@cfrancois7 you are correct, we can probably get away with just running git-cola rather than calling through python. If that fixes things for you, I'm tempted to tweak this code and just have it call into the script directly.

You may have noticed that the Makefile and launcher script goes through some machinations to launch itself.

"symlink to python, name the symlink 'git-cola', and exec through that symlink" is the strategy being used above. The reason we did that was that it would trick macOS into displaying "git-cola" in the application title bar (in older versions of macOS.. haven't tested that in a while).

That hack is pretty confusing and fragile, and as you note, it breaks things in your setup. I'm going to rip that part out.

@davvid davvid reopened this Mar 17, 2018

@davvid davvid closed this in c9d9fec Mar 17, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment