External command line py script still using maya's python??

368 views
Skip to first unread message

Benjam901

unread,
Jul 6, 2015, 7:43:02 AM7/6/15
to python_in...@googlegroups.com
Hello all,

So I am slightly stumped as to what is happening with my batch file.

I am running an export process from Maya that executes a batch file using subprocess. Inside the batch file is an execution to another python script that error checks the Maya export.

Running the batch using cmd  is great and works as expected.....however when I try to do this inside of the Maya script it throws an lxml error because of the python it is using.

I checked the python exe that it is using and it is using C:\Program Files\Autodesk\Maya2015\bin\python.exe which is strange because running python 'myscript.py' in the batch file should run using the machines python version.

The reason for running it through a .bat file is because I need it to be run as a standalone application as well as an under the hood checker.


Here is what my bat file looks like for the most part:
set PYTHONPATH=C:\Anaconda\Lib\site-packages;%UNITMANAGERPATH%\scripts;%UNITMANAGERPATH%\UI;

set FILEPATH=%1
set ARG=%2

python "%UNITMANAGERPATH%\scripts\__main__.py" %FILEPATH% %ARG%

And the execution line inside my maya python script:
def debugUnit(unitPath=''):
import subprocess
unitDebuggerBat = os.getenv('MAYATOOLSPATH')+'\\cmd\\unit_debugger.bat'
 
return subprocess.check_output([unitDebuggerBat, unitPath, 'False']).split('UNITERROR')[-1].strip()


Just incase the description was confusing here is the process:

Export from Maya > Run .bat file from the export script > run python error check script from .bat file

From what I am aware of running python "%UNITMANAGERPATH%\scripts\__main__.py" %FILEPATH% %ARG% should run using my machines Python which is Anaconda but it is using Maya's python which is very confusing.

Is there an additional command that I need to run in the .bat file to make it completely separate from Maya's python exe?

Any help would be much appreciated as always :)

Cheers!

Ben

Benjam901

unread,
Jul 6, 2015, 7:58:20 AM7/6/15
to python_in...@googlegroups.com
Edit: SOLVED

So I managed to solve it just after I published this post. For anyone needing a solution like this here is how I did it

I set the python command in the bat file to point directly to which python version I wanted to run and hey presto it works :)

set PYTHONVERSION=C:\Anaconda\python.exe

set FILEPATH=%1
set ARG=%2

%PYTHONVERSION% "%UNITMANAGERPATH%\scripts\__main__.py" %FILEPATH% %ARG%

Cheers,

Ben

Justin Israel

unread,
Jul 6, 2015, 4:15:49 PM7/6/15
to python_in...@googlegroups.com

It was most likely because the environment you were launching your subprocess within was bootstrapped to Maya, and the PATH and supporting PYTHON env keys were still going to have you pick up Maya's python. Not the system python. Using the full path to the desired interpreter is one way around it. Setting PATH is probably another.


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/d692c3ab-7373-42f0-ae18-e02d140d3f47%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ben Hearn

unread,
Jul 8, 2015, 5:27:38 AM7/8/15
to python_in...@googlegroups.com
Thanks for the tips I will keep that in mind!

--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/0WnLb13QUeY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3QMc1joH64s1D0q9TDtrCGDB10P52-BO2fCYUJnxSsgg%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.



--

Tel - +46 76245 92 90 (Sweden)
Reply all
Reply to author
Forward
0 new messages