PixarAnimationStudios / OpenUSD

Universal Scene Description
http://www.openusd.org
Other
5.99k stars 1.18k forks source link

usdview on macOS 10.14.6 - ImportError: cannot import name QtCore #1111

Closed sttng closed 4 years ago

sttng commented 4 years ago

Description of Issue

Starting usdview will fail with ImportError:

Traceback (most recent call last):
  File "/opt/local/USD/bin/usdview", line 28, in <module>
    import pxr.Usdviewq as Usdviewq
  File "/opt/local/USD/lib/python/pxr/Usdviewq/__init__.py", line 26, in <module>
    from qt import QtWidgets
  File "/opt/local/USD/lib/python/pxr/Usdviewq/qt.py", line 26, in <module>
    from attributeValueEditorUI import QtCore
ImportError: cannot import name QtCore

Fix (for me)

Replacing the line below:

https://github.com/PixarAnimationStudios/USD/blob/be1a80f8cb91133ac75e1fc2a2e1832cd10d91c8/pxr/usdImaging/usdviewq/qt.py#L26

with

from PySide2 import QtCore

fixed the issue and usdview starts on macOS for me.

Steps to Reproduce

Install USD on macOS by following the instructions Test the installation by running: usdview extras/usd/tutorials/convertingLayerFormats/Sphere.usda

System Information (OS, Hardware)

macOS 10.14.6 (fresh install)

Package Versions

Not sure about the version, cloned the master branch from Github on 10th Feb 2020

Build Flags

python USD/build_scripts/build_usd.py /opt/local/USD

moddyz commented 4 years ago

Out of curiousity - if you add the following lines before from attributeValueEditorUI import QtCore:

import attributeValueEditorUI
print attributeValueEditorUI.__file__

What output do you see?

jilliene commented 4 years ago

Filed as internal issue #USD-5847

sttng commented 4 years ago

Out of curiousity - if you add the following lines before from attributeValueEditorUI import QtCore:

import attributeValueEditorUI
print attributeValueEditorUI.__file__

What output do you see?

Thats the output (in fact no output from those lines as far as I can see):

Tors-MBP:Pixar tor$ usdview
dyld: warning, LC_RPATH @executable_path/../Frameworks in /Library/Python/2.7/site-packages/PySide2/Qt/lib/QtQml.framework/Versions/5/QtQml being ignored in restricted program because of @executable_path
dyld: warning, LC_RPATH @executable_path/../Frameworks in /Library/Python/2.7/site-packages/PySide2/Qt/lib/QtNetwork.framework/Versions/5/QtNetwork being ignored in restricted program because of @executable_path
dyld: warning, LC_RPATH @executable_path/../Frameworks in /Library/Python/2.7/site-packages/PySide2/Qt/lib/QtCore.framework/Versions/5/QtCore being ignored in restricted program because of @executable_path
dyld: warning, LC_RPATH @executable_path/../Frameworks in /Library/Python/2.7/site-packages/PySide2/Qt/lib/QtGui.framework/Versions/5/QtGui being ignored in restricted program because of @executable_path
dyld: warning, LC_RPATH @executable_path/../Frameworks in /Library/Python/2.7/site-packages/PySide2/Qt/lib/QtWidgets.framework/Versions/5/QtWidgets being ignored in restricted program because of @executable_path
/opt/local/USD/lib/python/pxr/Usdviewq/attributeValueEditorUI.pyc
Traceback (most recent call last):
  File "/opt/local/USD/bin/usdview", line 28, in <module>
    import pxr.Usdviewq as Usdviewq
  File "/opt/local/USD/lib/python/pxr/Usdviewq/__init__.py", line 26, in <module>
    from qt import QtWidgets
  File "/opt/local/USD/lib/python/pxr/Usdviewq/qt.py", line 28, in <module>
    from attributeValueEditorUI import QtCore
ImportError: cannot import name QtCore
Tors-MBP:Pixar tor$ 
RyZeePy commented 4 years ago

I'm hitting this same issue. It seems that .../lib/python/pxr/Usdviewq/attributeValueEditorUI.py (generated by uic) does not import QtCore directly into it's global scope. The imports are as below:

from PySide2.QtCore import (QCoreApplication, QMetaObject, QObject, QPoint,
    QRect, QSize, QUrl, Qt)
from PySide2.QtGui import (QBrush, QColor, QConicalGradient, QCursor, QFont,
    QFontDatabase, QIcon, QLinearGradient, QPalette, QPainter, QPixmap,
    QRadialGradient)
from PySide2.QtWidgets import *

Perhaps imports are being generated differently by uic in newer versions of PySide2?

Using: Fedora 31 (kernel 5.4.17-200.fc31.x86_64) USD-20.02 PySide2-5.14.1

Can provide more info upon request.

danlee-lils commented 4 years ago

I am getting the same issue here...

sunyab commented 4 years ago

Hi all, thanks for the reports, we're observed this issue on our side as well and are looking into a fix. For the folks who are running into this, are you using PySide2 5.14.1? The test environment where we're hitting this is using 5.14.1, and I see @seymour88 is as well.

danlee-lils commented 4 years ago

Yes I am using pyside2 5.14.1.

meshula commented 4 years ago

I can confirm from multiple sources that 5.13.2 is the latest that works on macOS, later than that, it's broken.

danlee-lils commented 4 years ago

cool thank you for the information!!

robpieke commented 4 years ago

I can confirm from multiple sources that 5.13.2 is the latest that works on macOS, later than that, it's broken.

They (Qt) switched from a bespoke pyside2-uic to uic (with python support) in 5.14

https://bugreports.qt.io/browse/PYSIDE-1098 https://github.com/qt/qtbase/blob/dev/src/tools/uic/python/pythonwriteimports.cpp#L41

sttng commented 4 years ago

Yeah also using PySide2 5.14.1 (https://download.qt.io/official_releases/QtForPython/pyside2/PySide2-5.14.1-5.14.1-cp27-cp27m-macosx_10_13_intel.whl) here. That seems to be the culprit.

jackiezxt commented 4 years ago

I'm hitting the same issue on macOS 10.15, but I was successfully built the usd-core on win10 with flags like this python build_usd.py C:\USD --build-args boost,"--with-date_time --with-thread --with-system --with-filesystem" but I faild on macos with python USD/build_scripts/build_usd.py /opt/local/USD they are the same branch from GitHub......

USD-20.02 PySide2-5.14.1 macOS-10.15 catalina

sttng commented 4 years ago

I'm hitting the same issue on macOS 10.15, but I was successfully built the usd-core on win10 with flags like this python build_usd.py C:\USD --build-args boost,"--with-date_time --with-thread --with-system --with-filesystem" but I faild on macos with python USD/build_scripts/build_usd.py /opt/local/USD they are the same branch from GitHub......

USD-20.02 PySide2-5.14.1 macOS-10.15 catalina

I guess if your build fails this is a Python 2 vs Python 3 issue. Catalina comes with Python 3 standard, and USD still relies on Python 2. Anyhow the issue dicsussion here is not a issue of failed building (actually the build is successful), but an issue in running usdview - after successful build. I suggest to create a new issue and add the output of errors you receive from building.

jackiezxt commented 4 years ago

Hi, @sttng I'm running python 2.7.16, the same running usdview error after successful build on macos

danlee-lils commented 4 years ago

downgrade your pyside2 to 5.13.2 and rebuild the whole USD and it should work.

jackiezxt commented 4 years ago

downgrade your pyside2 to 5.13.2 and rebuild the whole USD and it should work.

Thank you @danlee-lils, Bingo!, it's done, I pip uninstall the 5.14.1, and pip install the pyside2==5.13.2, usdview became alive and works.

sunyab commented 4 years ago

We have a fix for this issue checked in internally and will be pushing out to GitHub in the next few days.

aka-anoop commented 4 years ago

downgrade your pyside2 to 5.13.2 and rebuild the whole USD and it should work.

Works like a charm. Thank you.

Will wait for the fix as well @sunyab 👍

spitzak commented 3 years ago

This is a failure in the code to detect whether PySide or PySide2 is in use that does not work for PySide2 after 5.13. Removing the test will make it unable to work with one of these. My proposed patch to qt.py:

@@ -23,9 +23,13 @@
 #

 # Import a UI file generated by the build to detect which version of PySide to use.
-from attributeValueEditorUI import QtCore
+try:
+    from attributeValueEditorUI import QtCore
+    pyside1 = QtCore.__name__.startswith('PySide.')
+except:
+    pyside1 = False

-if QtCore.__name__.startswith('PySide.'):
+if pyside1:
     from PySide import QtGui, QtOpenGL
     from PySide import QtGui as QtWidgets

@@ -53,13 +57,11 @@
     if not hasattr(QtCore, 'QStringListModel'):
         QtCore.QStringListModel = QtGui.QStringListModel

-elif QtCore.__name__.startswith('PySide2.'):
-    from PySide2 import QtGui, QtWidgets, QtOpenGL
+else:
+    from PySide2 import QtCore, QtGui, QtWidgets, QtOpenGL

     # Older versions still have QtGui.QStringListModel - this
     # is apparently a bug:
     #    https://bugreports.qt.io/browse/PYSIDE-614
     if not hasattr(QtCore, 'QStringListModel'):
         QtCore.QStringListModel = QtGui.QStringListModel
-else:
-    raise ImportError()
brainteaser1990 commented 2 years ago

I got this error again, any solutions ??

usdview -h Traceback (most recent call last): File "/usr/local/USD/bin/usdview", line 28, in import pxr.Usdviewq as Usdviewq File "/usr/local/USD/lib/python/pxr/Usdviewq/init.py", line 32, in from .qt import QtWidgets, QtCore File "/usr/local/USD/lib/python/pxr/Usdviewq/qt.py", line 42, in PySideModule = GetPySideModule() File "/usr/local/USD/lib/python/pxr/Usdviewq/qt.py", line 31, in GetPySideModule from . import attributeValueEditorUI File "/usr/local/USD/lib/python/pxr/Usdviewq/attributeValueEditorUI.py", line 1 /**** ^ SyntaxError: invalid syntax

not working with the pyside2 version change as well.