<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Error Message with Python: &amp;quot;OpenMaya.py line 21 DLL load failed&amp;quot; in Maya Forum</title>
    <link>https://forums.autodesk.com/t5/maya-forum/error-message-with-python-quot-openmaya-py-line-21-dll-load/m-p/7034011#M72221</link>
    <description>&lt;P&gt;I was dealing with this error in the context of running a Maya sub process from a compiled Python application.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I found was that without&amp;nbsp;'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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;import getpass
import&amp;nbsp;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()&lt;/PRE&gt;&lt;P&gt;That totally solved the issue for me in this context. Posting it here because others may run into this.....&lt;/P&gt;&lt;P&gt;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....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 21 Apr 2017 18:08:05 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2017-04-21T18:08:05Z</dc:date>
  </channel>
</rss>

