Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Pyinstaller and pymel.core. What the heck?

Pyinstaller and pymel.core. What the heck?

robotProdigy
Advocate Advocate
899 Views
1 Reply
Message 1 of 2

Pyinstaller and pymel.core. What the heck?

robotProdigy
Advocate
Advocate

(Windows 7, Maya 2014, Python 2.7)

I have a prototype of 2 python files. caller.py, that spawns another python program, worker.py, in the mayapy Python environment and are as follows.

 

caller.py

import subprocess, re, os
 
path_to_target_py = re.sub('[^\\\\/]*$', 'worker.py', os.path.realpath(__file__))
mayapy_path = r'C:\Program Files\Autodesk\Maya2014\bin\mayapy.exe'
 
cmd = [mayapy_path, '-u', path_to_target_py]
 
proc_obj = subprocess.Popen(cmd, stdout=subprocess.PIPE)
for line in iter(proc_obj.stdout.readline, ''):
                print(line)

worker.py

import maya.standalone
maya.standalone.initialize()

import maya.cmds as cm
print("cm = {0}".format(cm))

import pymel.core; #Crashes here
print("pymel.core = {0}".format(pymel.core))

 

After running caller.py, I see the following 2 lines which indicate the modules maya.cmds and pymel.core loaded (good).

cm = <module 'maya.cmds' from ...bla bla bla>
pymel.core = <module 'pymel.core' from ...bla bla bla>

 

But here's the catch. For my purposes, caller.py program needs to be converted to an executable, caller.exe via pyinstaller. I do this with the following line in a command prompt:

pyinstaller --onefile --clean caller.py


After creating caller.exe and running it, I get:

 

cm = <module 'maya.cmds' from 'C:\Program Files\Autodesk\Maya2014\Python\lib\site-packages\maya\cmds\__init__.pyc'>
Traceback (most recent call last):
  File "D:\Dropbox\settings and scripts\motionBuilder\ws\exporter_batch\150508\multithreaded_icaf_exporter\pyinstall_popen_test2_mayapy\worker.py", line 12, in <module>
    import pymel.core; #Crashes here
  File "C:\Program Files\Autodesk\Maya2014\Python\lib\site-packages\pymel\core\__init__.py", line 7, in <module>
    import pymel.internal.startup as _startup
  File "C:\Program Files\Autodesk\Maya2014\Python\lib\site-packages\pymel\internal\__init__.py", line 4, in <module>
    from plogging import getLogger
  File "C:\Program Files\Autodesk\Maya2014\Python\lib\site-packages\pymel\internal\plogging.py", line 5, in <module>
    import logging.config
  File "C:\Program Files\Autodesk\Maya2014\bin\python27.zip\logging\config.py", line 27, in <module>
  File "C:\Program Files\Autodesk\Maya2014\bin\python27.zip\logging\handlers.py", line 27, in <module>
  File "C:\Program Files\Autodesk\Maya2014\bin\python27.zip\socket.py", line 47, in <module>
ImportError: DLL load failed: The specified procedure could not be found.

 

Pretty bizarre that worker.py CAN import maya.cmds and CANNOT import pymel.core when spawned from caller.exe, but there is no problem when spawned from caller.py.

 

How in the world would maya even know what spawned worker.py, much less, no longer be able to find its own module pymel.core? 

But it gets weirder. if I change caller.py to this (it no longer reads stdout)...

import subprocess, re, os
 
path_to_target_py = re.sub('[^\\\\/]*$', 'worker.py', os.path.realpath(__file__))
mayapy_path = r'C:\Program Files\Autodesk\Maya2014\bin\mayapy.exe'
 
cmd = [mayapy_path, '-u', path_to_target_py]
 
proc_obj = subprocess.Popen(cmd)

then convert that to caller.exe, worker.py is now able to import pymel (as well as maya.cmds) when spawned from caller.exe that no longer reads stdout.

Beyond confused at this point. Anyone know what's going on or how to get around this?


Cheers,
Paul

900 Views
1 Reply
Reply (1)
Message 2 of 2

robotProdigy
Advocate
Advocate

I never could nail down what was causing the problem other than pyinstaller doesn't like it when the new executable tries to import pymel.core in the mayapy environment. Where I was failing with pyinstaller, I am succedding with py2exe.  I'll check my post off as solved once get my tool fully working with py2exe.