Repository: spyder-ide/spyder

Issue:
PySide2 error when viewing dataframes in Python 3.10
I have got a problem with spyder's variable explorer and it seems to be different from the others on the issue board:

When I try to visualize a dataframe (in variable explorer) clicking on it, a popup appears saying "spyder has encountered an internal problem"

The traceback is:

```
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/spyder/plugins/variableexplorer/widgets/collectionsdelegate.py", line 203, in createEditor
    if not editor.setup_and_check(value, title=key):
  File "/usr/lib/python3.10/site-packages/spyder/plugins/variableexplorer/widgets/dataframeeditor.py", line 942, in setup_and_check
    self.create_data_table()
  File "/usr/lib/python3.10/site-packages/spyder/plugins/variableexplorer/widgets/dataframeeditor.py", line 1066, in create_data_table
    self.dataTable = DataFrameView(self, self.dataModel,
  File "/usr/lib/python3.10/site-packages/spyder/plugins/variableexplorer/widgets/dataframeeditor.py", line 532, in __init__
    self.setHorizontalScrollMode(1)
TypeError: 'PySide2.QtWidgets.QAbstractItemView.setHorizontalScrollMode' called with wrong argument types:
  PySide2.QtWidgets.QAbstractItemView.setHorizontalScrollMode(int)
Supported signatures:
  PySide2.QtWidgets.QAbstractItemView.setHorizontalScrollMode(PySide2.QtWidgets.QAbstractItemView.ScrollMode) 
```

  But from Pyside2 "setHorizontalScrollMode" documentation everything seems to be all right.
  I have tried different versions of Spyder (right now I have **Python 3.10.1 64-bit | Qt 5.15.2 | PySide2 5.15.2 | Linux 5.12.6-1-ck** ), maybe the problem is PySide2. It is doing it about since a couple of weeks ago.


Discussion:
Hey @ElMastro, thanks for reporting. I can't reproduce this problem with Python 3.8 and PySide2 5.15. And unfortunately, I can't install PySide2 for Python 3.10 using pip to test.

You said

> maybe the problem is PySide2. It is doing it about since a couple of weeks ago.

Yeah, that's most probably the case. PySide2 is experimental, so not assured to work flawlessly.
Please try to change this line

```python
self.setHorizontalScrollMode(1)
```

in `spyder/plugins/variableexplorer/widgets/dataframeeditor.py` for this one

```python
self.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel)
```

(importing `QAbstractItemView` from `QtWidgets` first, of course). That could help.

If not, please downgrade to Python 3.9 if you want to keep using Pyside2, or switch to PyQt5.
My system says that QtWarning can't be imported,


I believe my PySide2 package is damaged. I would like to pass to PyQt5, but qtpy package doesn't recognize it:

"  File "/usr/lib/python3.10/site-packages/qtpy/__init__.py", line 216, in <module>
    raise PythonQtError('No Qt bindings could be found')
"
I would like to try it if I could make it work
________________________________
Da: Carlos Cordoba ***@***.***>
Inviato: giovedì 6 gennaio 2022 04:54
A: spyder-ide/spyder ***@***.***>
Cc: ElMastro ***@***.***>; Mention ***@***.***>
Oggetto: Re: [spyder-ide/spyder] Variable explorer crash on dataframes (Issue #17139)


Hey @ElMastro<https://github.com/ElMastro>, thanks for reporting. I can't reproduce this problem with Python 3.8 and PySide2 5.15. And unfortunately, I can't install PySide2 for Python 3.10 using pip to test.

You said

maybe the problem is PySide2. It is doing it about since a couple of weeks ago.

Yeah, that's most probably the case. PySide2 is experimental, so not assured to work flawlessly.

—
Reply to this email directly, view it on GitHub<https://github.com/spyder-ide/spyder/issues/17139#issuecomment-1006264489>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AKYXXCUYHCBQZN2T6K74763UUUHA3ANCNFSM5LKIRUPA>.
Triage notifications on the go with GitHub Mobile for iOS<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you were mentioned.Message ID: ***@***.***>

> I believe my PySide2 package is damaged. I would like to pass to PyQt5, but qtpy package doesn't recognize i

Do you have PyQt5 installed?
Yes, I installed it yesterday evening. Unfortunately seems like qtpy searches for Pyside, and exporting "QT_API=qtpy5" doesn't make it change its idea...
Il 7 gen 2022, 00:53 +0100, Carlos Cordoba ***@***.***>, ha scritto:
> > I believe my PySide2 package is damaged. I would like to pass to PyQt5, but qtpy package doesn't recognize i
> Do you have PyQt5 installed?
> —
> Reply to this email directly, view it on GitHub, or unsubscribe.
> Triage notifications on the go with GitHub Mobile for iOS or Android.
> You are receiving this because you were mentioned.Message ID: ***@***.***>

Then remove Pyside2 to see what happens. 
Mr Cordoba,
there is amisunderstanding, what I've done is:

-I installed Qtpy5
-I removed  PySide2 and Pyside2-tools
-Now wehn I run spyder it says:
"Traceback (most recent call last):
  File "/usr/bin/spyder", line 33, in <module>
    sys.exit(load_entry_point('spyder==5.2.0', 'gui_scripts', 'spyder')())
  File "/usr/lib/python3.10/site-packages/spyder/app/start.py", line 232, in main
    from spyder.app import mainwindow
  File "/usr/lib/python3.10/site-packages/spyder/app/mainwindow.py", line 41, in <module>
    requirements.check_qt()
  File "/usr/lib/python3.10/site-packages/spyder/requirements.py", line 47, in check_qt
    if parse_version(actual_ver) < parse_version(required_ver):
  File "/usr/lib/python3.10/site-packages/pkg_resources/__init__.py", line 114, in parse_version
    return packaging.version.Version(v)
  File "/usr/lib/python3.10/site-packages/packaging/version.py", line 296, in __init__
    match = self._regex.search(version)
TypeError: expected string or bytes-like object


________________________________
Da: Carlos Cordoba ***@***.***>
Inviato: venerdì 7 gennaio 2022 15:30
A: spyder-ide/spyder ***@***.***>
Cc: ElMastro ***@***.***>; Mention ***@***.***>
Oggetto: Re: [spyder-ide/spyder] PySide2 error when viewing dataframes (Issue #17139)


Then remove Pyside2 to see what happens.

—
Reply to this email directly, view it on GitHub<https://github.com/spyder-ide/spyder/issues/17139#issuecomment-1007449313>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AKYXXCVQEZDVZKUVWKJEZBDUU32JRANCNFSM5LKIRUPA>.
Triage notifications on the go with GitHub Mobile for iOS<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you were mentioned.Message ID: ***@***.***>

This part of your error

```
  File "/usr/lib/python3.10/site-packages/pkg_resources/__init__.py", line 114, in parse_version
    return packaging.version.Version(v)
  File "/usr/lib/python3.10/site-packages/packaging/version.py", line 296, in __init__
    match = self._regex.search(version)
TypeError: expected string or bytes-like object
```

indicates that there's a problem either with the `pkg_resources` package provided by your Linux distro or perhaps with QtPy one.

What command did you use to install Spyder?
I installed it compiling the AUR Package spuder-git, which runs a setup py file. However I just tested the compiled package installed with pacman (my package manager in archbang). Maybe the problem is with Qtpy?
Il 7 gen 2022, 22:38 +0100, Carlos Cordoba ***@***.***>, ha scritto:
> This part of your error
>  File "/usr/lib/python3.10/site-packages/pkg_resources/__init__.py", line 114, in parse_version
>    return packaging.version.Version(v)
>  File "/usr/lib/python3.10/site-packages/packaging/version.py", line 296, in __init__
>    match = self._regex.search(version)
> TypeError: expected string or bytes-like object
> indicates that there's a problem either with the pkg_resources package provided by your Linux distro or perhaps with QtPy one.
> What command did you use to install Spyder?
> —
> Reply to this email directly, view it on GitHub, or unsubscribe.
> Triage notifications on the go with GitHub Mobile for iOS or Android.
> You are receiving this because you were mentioned.Message ID: ***@***.***>

Nop, that's not the problem either: I installed Spyder with PyQt 5.15 and QtPy 2.0 in Python 3.8 and it's working without problems.

Please report this problem with your Linux distro maintainers because it seems to be caused by it. If you want to use Spyder with a set of dependencies that's tested to work, please use Anaconda or pip in a virtualenv (Linux distros usually break Spyder by forcing it to work with dependencies it's not prepared to).
Mr Cordoba, maybe that if I run
'pip install pyqt5 qtpy spyder' it would reinstall everything and  make it work?
Il 9 gen 2022, 18:18 +0100, Carlos Cordoba ***@***.***>, ha scritto:
> Nop, that's not the problem either: I installed Spyder with PyQt 5.15 and QtPy 2.0 in Python 3.8 and it's working without problems.
> Please report this problem with your Linux distro maintainers because it seems to be caused by it. If you want to use Spyder with a set of dependencies that's tested to work, please use Anaconda or pip in a virtualenv (Linux distros usually break Spyder by forcing it to work with dependencies it's not prepared to work with).
> —
> Reply to this email directly, view it on GitHub, or unsubscribe.
> Triage notifications on the go with GitHub Mobile for iOS or Android.
> You are receiving this because you were mentioned.Message ID: ***@***.***>

Yes, but using a virtualenv.
Mr. Cordoba,
I am incredibly sorry; I would like to apologize, because I found how to solve the problem:

In the end it resulted that it was as you said, I run
"pip uninstall qtpy pyqt5" an installing everything anew made the problem disappear;
Thank you for your time,

Marco
________________________________
Da: Carlos Cordoba ***@***.***>
Inviato: domenica 9 gennaio 2022 21:59
A: spyder-ide/spyder ***@***.***>
Cc: ElMastro ***@***.***>; Mention ***@***.***>
Oggetto: Re: [spyder-ide/spyder] PySide2 error when viewing dataframes in Python 3.10 (Issue #17139)


Yes, but using a virtualenv.

—
Reply to this email directly, view it on GitHub<https://github.com/spyder-ide/spyder/issues/17139#issuecomment-1008422515>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AKYXXCQJ3CB2V5QKDRKEQATUVHZM5ANCNFSM5LKIRUPA>.
Triage notifications on the go with GitHub Mobile for iOS<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you were mentioned.Message ID: ***@***.***>

This is resolved by changing `1` to `QTableView.ScrollPerPixel` [in these 2 lines](https://github.com/spyder-ide/spyder/blob/094f45e102f3e7cf36f817f97435a814f13ac5f7/spyder/plugins/variableexplorer/widgets/dataframeeditor.py#L538-L539).

I checked this fix works with Python 3.10.2 64-bit | Qt 5.15.2 | PySide2 5.15.2.1 | Windows 10 that came with WinPython 64-3.10.2.0. 

Should I submit PR?
Hey @fumitoh, yes, please do submit a PR. And thanks a lot for your help!

Resolving patch:
diff --git a/spyder/plugins/variableexplorer/widgets/dataframeeditor.py b/spyder/plugins/variableexplorer/widgets/dataframeeditor.py
--- a/spyder/plugins/variableexplorer/widgets/dataframeeditor.py
+++ b/spyder/plugins/variableexplorer/widgets/dataframeeditor.py
@@ -535,8 +535,8 @@ def __init__(self, parent, model, header, hscroll, vscroll):
         self.setModel(model)
         self.setHorizontalScrollBar(hscroll)
         self.setVerticalScrollBar(vscroll)
-        self.setHorizontalScrollMode(1)
-        self.setVerticalScrollMode(1)
+        self.setHorizontalScrollMode(QTableView.ScrollPerPixel)
+        self.setVerticalScrollMode(QTableView.ScrollPerPixel)
 
         self.sort_old = [None]
         self.header_class = header


Test patch: