Have to add tons of environ variable to make qml works as expected. Is this a normal case? (Maya 2022, python3.7)

I was having trouble in the pyblish_qml + pyblish_maya setup.

In order to get the GUI show up, I have to set up all the dependencies of PyQt5 into env var like this

import os
import sys
import pyblish.api

pyblish.api.register_gui("pyblish_qml")

# Add to Maya
sys.path.insert(0, r"~\packages\pyblish_qml\1.11.5\python-3.7\python")
sys.path.insert(0, r"~\packages\pyblish_base\1.8.8\python-3.7\python")
sys.path.insert(0, r"~\packages\pyblish_maya\2.1.8\python-3.7\python")

sys.path.insert(0, r"~\packages\PyQt5_sip\12.9.0\platform-windows\arch-AMD64\python-3.7\python")
sys.path.insert(0, r"~\packages\PyQt5_Qt5\5.15.2\platform-windows\arch-AMD64\python-3.7\python")
sys.path.insert(0, r"~\packages\PySide2\5.15.2\platform-windows\arch-AMD64\python-3.7\python")


# Add to Pyblish QML
os.environ["PYTHONPATH"] = r"~\packages\pyblish_qml\1.11.5\python-3.7\python"
os.environ["PYTHONPATH"] += r";~\packages\pyblish_base\1.8.8\python-3.7\python"
os.environ["PYTHONPATH"] += r";~\packages\pyblish_maya\2.1.8\python-3.7\python"
os.environ["PYTHONPATH"] += r";~\packages\PySide2\5.15.2\platform-windows\arch-AMD64\python-3.7\python"

os.environ["PYTHONPATH"] += r";~\packages\PyQt5_Qt5\5.15.2\platform-windows\arch-AMD64\python-3.7\python"
os.environ["PYTHONPATH"] += r";~\packages\PyQt5_sip\12.9.0\platform-windows\arch-AMD64\python-3.7\python"

from pyblish_qml import api, show
api.register_python_executable(r"~/apps/studio/prod/python/3.7.7/platform-windows/python.exe")
api.register_pyqt5(r"~\packages\PyQt5\5.15.4\platform-windows\arch-AMD64\python-3.7\python")

import pyblish_maya
pyblish_maya.setup()

If I simply do this two

import pyblish.api
import pyblish_maya
pyblish.api.register_gui("pyblish_qml")
from pyblish_qml import api, show
api.register_python_executable(r"~/apps/studio/prod/python/3.7.7/platform-windows/python.exe")
api.register_pyqt5(r"~\packages\PyQt5\5.15.4\platform-windows\arch-AMD64\python-3.7\python")

there will be an error message saying “This application fialed to start because no Qt Platform plugin could be initialized. Reinstalling the aplication may fix this problem.”

1. Is that a normal case that I have to set up all these PyQt5_* dependencies?**

[Solved] 2. Even though I got the window pops up, the windows contains nothing.
It might be caused by the PySide2/init.py: Unable to import shiboken2 from ~\packages\pyblish_qml\1.11.5\python-3.7\python\pyblish_qml\ipc, …, But I’m not 100% sure about this.

Update 2021/07/23 17:06 : Alright that’s exactly the problem. Now I have to have two more PYTHONPATH be added to make this works.

sys.path.insert(0, r"~\packages\shiboken2\5.15.2\platform-windows\arch-AMD64\python-3.7\python")
os.environ["PYTHONPATH"] += r";~\packages\shiboken2\5.15.2\platform-windows\arch-AMD64\python-3.7\python"

[Solved] 3. Meanwhile I will have lite window working with simply these lines

import pyblish.api
pyblish.api.register_gui("pyblish_lite")

import pyblish_maya
pyblish_maya.setup()

Hi @cc886, sorry for the delayed reply, holiday times.

There appears to be both PyQt5 and PySide2 bindings in your snippet above, only one is required and two may even break things. Have a look here for a recent working combination.

Is that a normal case that I have to set up all these PyQt5_ * dependencies?**

Everyone does it differently, this is a perfectly valid approach. I’ve had best results by building an environment outside of Maya first, rather than from within Python. That way, the environment looks the same for all DCCs.

Thank you for your reply.

I am now facing with another problem. I suddently realized what has happend during those os.environ["PYTHONPATH"] =...

I wrongly overwrite the PYTHONPATH using = in the first line instead of +=, which completely remove other important PYTHONPATH variables, and there must be something not compatible with pyblish/qt module and cause error like this:

%E6%8D%95%E8%8E%B7

I think I have to figure out what package caused this issue.


  1. The script working, but it wrongly OVERWRTIE PYTHONPATH. I have checked the PYTHONPATH before I entering those os.environ["PYTHONPATH"], which actually already include the module paths.
import os
import sys

# Add to Pyblish QML
os.environ["PYTHONPATH"] = r";s:/apps/studio/beta/pyblish_qml/1.11.5/python-3.7/python"   ## Here I wrote the = but not +=, and if I changing it to += problem occurs. There must be some other package not capable here
os.environ["PYTHONPATH"] += r";s:/apps/studio/beta/pyblish_base/1.8.8/python-3.7/python"
os.environ["PYTHONPATH"] += r";s:/apps/studio/beta/pyblish_maya/2.1.8/python-3.7/python"
os.environ["PYTHONPATH"] += r";s:/apps/studio/beta/PySide2/5.15.2/platform-windows/arch-AMD64/python-3.7/python"
os.environ["PYTHONPATH"] += r";s:/apps/studio/beta/shiboken2/5.15.2/platform-windows/arch-AMD64/python-3.7/python"

import pyblish_maya, pyblish_qml, PySide2
import pyblish.api
pyblish.api.register_gui("pyblish_qml")

import pyblish_qml.api
pyblish_qml.api.register_python_executable(r"s:/apps/studio/prod/python/3.7.7/platform-windows/python.exe")

import pyblish_maya
pyblish_maya.setup()

Follow up:

I checker the os.PYTHONPATH one by one. And I found out what the problem is.

C:\Program Files\Autodesk\Maya2022\Python37\Lib\site-packages is located in a very front position in the PYTHONPATH, where I have (not sure how they installed as site-packages, maybe Maya2022 already have them?) another two folder called PySide2 and shiboken2 located there, which must have conflict with the rez env packages and cause that error.

I am now trying to find an elegant way to fix this issue.


Update: Simply prepend external PySide2 module path before Maya site-packages path into the PYTHONPATH cannot get this solved. Instead, Maya will crash when start up.