Skip to content

PyQt5 and pandas #16322

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

Closed
dibgerge opened this issue May 10, 2017 · 6 comments
Closed

PyQt5 and pandas #16322

dibgerge opened this issue May 10, 2017 · 6 comments
Labels
Duplicate Report Duplicate issue or pull request
Milestone

Comments

@dibgerge
Copy link

dibgerge commented May 10, 2017

I just updated my conda installation to Pandas 0.20.1, and it does not load anymore since it depends on PyQt4 which was updated to PyQt5.

To make Pandas 0.20.1 load with PyQt5, I have to modify a function within the pandas.io.clipboard.clipboards module as follows:

Modified function within pandas.io.clipboard.clipboards

def init_qt_clipboard():
    # $DISPLAY should exist
    from PyQt5.QtWidgets import QApplication

    # use the global instance if it exists
    app = QApplication.instance() or QApplication([])

    def copy_qt(text):
        cb = app.clipboard()
        cb.setText(text)

    def paste_qt():
        cb = app.clipboard()
        return text_type(cb.text())

    return copy_qt, paste_qt

Problem description

The current behavior requires PyQt4 by default, even if it is not needed to be used, which was giving me the error when import pandas:

ImportError: No module named 'PyQt4.QtGui'.

Changing the module as described above solved the problem.

@jorisvandenbossche
Copy link
Member

@dibgerge Thanks for the report. This has (as far as we know) not actually to do with pandas, but we did already fix it by not importing the clipboard (and thus PyQt) functionality on import time (but only when you actually use the read/to_clipboard functionality. See #16294 and #16288

The reason (at least in my case) you get the error is because import PyQt4 works, but from PyQt4 import QtCore, QtGui failed (I had for some reason an empty PyQt4 directory in my site-packages, maybe leftover from an update).

@jorisvandenbossche jorisvandenbossche added the Duplicate Report Duplicate issue or pull request label May 10, 2017
@jorisvandenbossche jorisvandenbossche added this to the 0.20.2 milestone May 10, 2017
@dibgerge
Copy link
Author

@jorisvandenbossche Thank you for your clarification. Yes, that is what I have also. It looks like Conda deleted my PyQt4 module content but left the directory when it installed PyQt5.

@jorisvandenbossche
Copy link
Member

Thanks for the confirmation, seems we had the same problem. Although I really don't know how conda can end up there. (tried in in a clean env to first install pyqt 4 and then update, but can't reproduce)

@kalefranz
Copy link

@jorisvandenbossche @dibgerge I know it won't be exact, but could you give me a rough idea of the conda version you were using? Or just conda info.

@jorisvandenbossche
Copy link
Member

Closing this, as further discussion can go on conda/conda#5290 (and in 0.20.2 will already be a fix to not do the PyQt4 check on main pandas import)

@Nikhilkumar8143
Copy link

I just updated my conda installation to Pandas 0.20.1, and it does not load anymore since it depends on PyQt4 which was updated to PyQt5.

To make Pandas 0.20.1 load with PyQt5, I have to modify a function within the pandas.io.clipboard.clipboards module as follows:

Modified function within pandas.io.clipboard.clipboards

def init_qt_clipboard():
    # $DISPLAY should exist
    from PyQt5.QtWidgets import QApplication

    # use the global instance if it exists
    app = QApplication.instance() or QApplication([])

    def copy_qt(text):
        cb = app.clipboard()
        cb.setText(text)

    def paste_qt():
        cb = app.clipboard()
        return text_type(cb.text())

    return copy_qt, paste_qt

Problem description

The current behavior requires PyQt4 by default, even if it is not needed to be used, which was giving me the error when import pandas:

ImportError: No module named 'PyQt4.QtGui'.

Changing the module as described above solved the problem.

Even I am having the same problem,I tried doing in your way but the current version already adds with try and catch block for pyqt.Please reply me I need to have a solution for this:

AttributeError: partially initialized module 'pandas' has no attribute 'plotting' (most likely due to a circular import)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

4 participants