PySide module import error: DLL load failed: %1 is not a valid Win32 application

I’m trying to make some simple UI tools in Unreal using PySide and Qt Designer. However I can’t seem to be able to import any PySide modules. For instance, if I run this code:

import sys
from PySide import QtGui

…I always get this error:

LogPython: Error: ImportError: DLL load failed: %1 is not a valid Win32 application.

I discovered I had a 32 bit version of Python 2.7 installed, so I initially thought the culprit could be a bit version mismatch issue between Python and PySide (32 bit Python with 64 bit PySide). I couldn’t figure out how to check the bit version of PySide, so to be safe I reinstalled both Python and PySide using their 64 bit installers. But after doing that I still get the same error.

Any ideas about what I’m doing wrong?

I just pip installed PySide under the unreal engine installed python.

C:\Program Files\Epic Games\UE_4.21\Engine\Source\ThirdParty\Python\Win64>python -m pip install --upgrade pip
C:\Program Files\Epic Games\UE_4.21\Engine\Source\ThirdParty\Python\Win64>python -m pip install PySide

Thanks, that did the trick. I had not realised that UE was using its own Python installation instead of the one from the OS, which makes complete sense now that I think about it.

I just tested import sys and append sys.path,is worked
It is found that the results are feasible
I think UE python read PC dir ,not UE dir

To make it short, it means that you lacked some “dependencies” for the libraries you wanted to use. This is a common problem when installing python packages, mainly in windows. Before trying to use any kind of library, first it is suggested to look up whether it needs another library in python “family”.

The solution is to provide the python interpreter with the path-to-your-module/library. The simplest solution is to append that python path to your sys.path list. In your notebook, first try:

import sys

This isn’t a permanent change in sys.path, because when you log out, your environment is reset, so any variables you may have set are lost.

The better (and more permanent) way to solve this is to set your PYTHONPATH, which provides the interpreter with additional directories look in for python packages/modules.

from BASH type: export PYTHONPATH=/path/to/new/folder:/another/path/...../ #each path must be separated by a colon