I was dealing with this error in the context of running a Maya sub process from a compiled Python application.
What I found was that without 'SYSTEMDRIVE': 'C:' in your os.environ, this error would happen. So when you call a subprocess from a compiled Python program, create a dictionary of the environment and pass that to the subprocess.
Example:
import getpass
import winpaths
import subprocess
processEnvironment = {
'SYSTEMROOT': '%s' % str(winpaths.get_windows()), #'C:\\windows'
'USERNAME': '%s' % getpass.getuser(),
'PATH':'%s\\python;%s\\python\\com\\lib;%s\\python\\com\\lib\\PySide2;' % (com.forge.config.getToolRoot(), com.forge.config.getToolRoot(), com.forge.config.getToolRoot()),
'PYTHONPATH': '%s\\python;%s\\python\\com\\lib;%s\\python\\com\\lib\\PySide2' % (com.forge.config.getToolRoot(), com.forge.config.getToolRoot(), com.forge.config.getToolRoot()),
'QT_QPA_PLATFORM_PLUGIN_PATH': '%s\\python\\com\\lib\\PySide2\\plugins\\platforms' % com.forge.config.getToolRoot(),
'QTDIR': '%s\\python\\com\\lib\\PySide2' % com.forge.config.getToolRoot(),
'USERPROFILE': '%s' % str(winpaths.get_user_profile()), # 'C:\\Users\\userName'
'APPDATA': '%s' % str(winpaths.get_appdata()), # 'C:\\Users\\userName\\AppData\\Roaming'
'LOCALAPPDATA': '%s' % str(winpaths.get_local_appdata()), # 'C:\\Users\\userName\\AppData\\Local'
'TMP': '%s\\Temp' % str(winpaths.get_local_appdata()), # 'C:\\Users\\userName\\AppData\\Local\\Temp'
'TEMP': '%s\\Temp' % str(winpaths.get_local_appdata()), # 'C:\\Users\\userName\\AppData\\Local\\Temp'
'WINDIR': '%s' % str(winpaths.get_windows()), #'C:\\windows'
'SYSTEMDRIVE': '%s:' % str(winpaths.get_windows()).split(':')[0] # 'C:'
}
mayaProcess = subprocess.Popen(
[
mayaPyPath.replace('/', '\\\\'),
'%s/python/com/forge/maya/characterize.py' % com.forge.config.getToolRoot().replace('\\', '/'),
self._preferences.activeBridge.sourceSkeletonPath,
self._preferences.activeBridge.sourceCharacterDefinitionPath,
'sourceCharacter',
sourceOutputPath
],
env=processEnvironment,
shell=True,
stdout=subprocessLogHandle,
stderr=subprocess.STDOUT
)
mayaProcess.wait()
That totally solved the issue for me in this context. Posting it here because others may run into this.....
You can ignore all the Qt stuff in there - we are using the same PySide2 version external to Maya with Python 2.7.12 that is why those env variables are in there....