Maya and PYTHONHOME

599 views
Skip to first unread message

Joe Weidenbach

unread,
Sep 1, 2018, 6:36:34 PM9/1/18
to Python Programming for Autodesk Maya

Hey all,

During a recent bout of programming zealousness, I blew away most of my previous mess of an environment and set myself to a cleaner package-based install. Now, I’ve loaded maya for the first time since, and it can’t load python properly. There was a previous post in here about this for Maya 2013, but this is for 2018, and I’d rather not resurrect a really old thread.

I’m on windows for this machine, but again I suspect that it’s a more widespread issue as I have replicated it on Linux.

The package manager (chocolatey) set up python with the PYTHONHOME environment variable, so now Maya can’t find it’s python libraries.

The stack trace:

Could not find maya.utils._guiExceptHook.
Invalid Python Environment: Python is unable to find Maya's Python modules
Python Environment:
  PYTHONHOME = C:\Python27
  PYTHONPATH = ;C:/Program Files/Autodesk/Maya2018/plug-ins/ATF/scripts;C:/Program Files/Autodesk/Bifrost/Maya2018/scripts/boss;C:/Program Files/Autodesk/Bifrost/Maya2018/scripts/presets;C:/Program Files/Autodesk/Bifrost/Maya2018/scripts;C:/Program Files/Autodesk/Maya2018/plug-ins/MASH/scripts;d:/Users/joe/Documents/maya/modules/ZivaVFX-Maya-1_2/scripts;C:/Program Files/Autodesk/Maya2018/plug-ins/fbx/scripts;C:/Program Files/Autodesk/Maya2018/plug-ins/camd/scripts;C:/solidangle/mtoadeploy/2018/scripts;C:/ProgramData/Autodesk/ApplicationPlugins/ngskintools/Contents/scripts;C:/Program Files/Autodesk/Maya2018/plug-ins/camd/scripts;C:/Program Files/Autodesk/Maya2018/plug-ins/camd/scripts;C:/Program Files/Autodesk/Maya2018/plug-ins/substance/scripts;C:/Program Files/Autodesk/Maya2018/plug-ins/xgen/scripts/cafm;C:/Program Files/Autodesk/Maya2018/plug-ins/xgen/scripts/xgenm;C:/Program Files/Autodesk/Maya2018/plug-ins/xgen/scripts/xgenm/ui;C:/Program Files/Autodesk/Maya2018/plug-ins/xgen/scripts/xgenm/xmaya;C:/Program Files/Autodesk/Maya2018/plug-ins/xgen/scripts/xgenm/ui/ae;C:/Program Files/Autodesk/Maya2018/plug-ins/xgen/scripts/xgenm/ui/brushes;C:/Program Files/Autodesk/Maya2018/plug-ins/xgen/scripts/xgenm/ui/dialogs;C:/Program Files/Autodesk/Maya2018/plug-ins/xgen/scripts/xgenm/ui/fxmodules;C:/Program Files/Autodesk/Maya2018/plug-ins/xgen/scripts/xgenm/ui/tabs;C:/Program Files/Autodesk/Maya2018/plug-ins/xgen/scripts/xgenm/ui/util;C:/Program Files/Autodesk/Maya2018/plug-ins/xgen/scripts/xgenm/ui/widgets;C:/Program Files/Autodesk/Maya2018/plug-ins/xgen/scripts
  System modules located at: C:\Program Files\Autodesk\Maya2018\bin\python27.zip
  Search path (sys.path):
    C:\Program Files\Autodesk\Maya2018\bin
    C:\Python27\lib\site-packages\rez-2.0.rc1.39-py2.7.egg
    C:\Program Files\Autodesk\Maya2018\bin
    C:\Program Files\Autodesk\Maya2018\plug-ins\ATF\scripts
    C:\Program Files\Autodesk\Bifrost\Maya2018\scripts\boss
    C:\Program Files\Autodesk\Bifrost\Maya2018\scripts\presets
    C:\Program Files\Autodesk\Bifrost\Maya2018\scripts
    C:\Program Files\Autodesk\Maya2018\plug-ins\MASH\scripts
    d:\Users\joe\Documents\maya\modules\ZivaVFX-Maya-1_2\scripts
    C:\Program Files\Autodesk\Maya2018\plug-ins\fbx\scripts
    C:\Program Files\Autodesk\Maya2018\plug-ins\camd\scripts
    C:\solidangle\mtoadeploy\2018\scripts
    C:\ProgramData\Autodesk\ApplicationPlugins\ngskintools\Contents\scripts
    C:\Program Files\Autodesk\Maya2018\plug-ins\substance\scripts
    C:\Program Files\Autodesk\Maya2018\plug-ins\xgen\scripts\cafm
    C:\Program Files\Autodesk\Maya2018\plug-ins\xgen\scripts\xgenm
    C:\Program Files\Autodesk\Maya2018\plug-ins\xgen\scripts\xgenm\ui
    C:\Program Files\Autodesk\Maya2018\plug-ins\xgen\scripts\xgenm\xmaya
    C:\Program Files\Autodesk\Maya2018\plug-ins\xgen\scripts\xgenm\ui\ae
    C:\Program Files\Autodesk\Maya2018\plug-ins\xgen\scripts\xgenm\ui\brushes
    C:\Program Files\Autodesk\Maya2018\plug-ins\xgen\scripts\xgenm\ui\dialogs
    C:\Program Files\Autodesk\Maya2018\plug-ins\xgen\scripts\xgenm\ui\fxmodules
    C:\Program Files\Autodesk\Maya2018\plug-ins\xgen\scripts\xgenm\ui\tabs
    C:\Program Files\Autodesk\Maya2018\plug-ins\xgen\scripts\xgenm\ui\util
    C:\Program Files\Autodesk\Maya2018\plug-ins\xgen\scripts\xgenm\ui\widgets
    C:\Program Files\Autodesk\Maya2018\plug-ins\xgen\scripts
    C:\Program Files\Autodesk\Maya2018\bin\python27.zip
    C:\Python27\DLLs
    C:\Python27\lib
    C:\Python27\lib\plat-win
    C:\Python27\lib\lib-tk
    C:\Python27
    C:\Python27\lib\site-packages

There’s a huge number of these in the output, I expect it’s one per call to Python.

I’d not expect that unsetting PYTHONHOME is expected/required by autodesk (although this disproves that theory), as the whole point of shipping mayapy is to get away from requiring the system install of python (other benefits include things like being able to use a python compiled with VC15, allowing the use of PySide2). The question in my mind would be, has anyone found a way to isolate Maya from the system python environment so it can be run side by side with other development tools that require PYTHONHOME or other features like this? I can’t imagine it’s that rare of a need.

Also, I tried to work through this with no luck: Python from an external interpreter. It seems that something in 2018 completely breaks using an external interpreter that could, for example, use virtualenvs to manage dependencies (this did work as recently as 2016).

Thanks in advance,

Joe

Justin Israel

unread,
Sep 1, 2018, 7:15:19 PM9/1/18
to python_in...@googlegroups.com
From reading the docs it seems to be the opposite. Mayapy is shipped to ensure Maya is correctly bootstrapped for standalone python usage by providing the correct version of python along with the location of the Maya libs. 


(other benefits include things like being able to use a python compiled with VC15, allowing the use of PySide2). The question in my mind would be, has anyone found a way to isolate Maya from the system python environment so it can be run side by side with other development tools that require PYTHONHOME or other features like this?

What happens if you set PYTHONHOME explicitly to Maya's location in the Maya.env file (similar to what mayapy does)? 

I would have expected Maya to always set PYTHONHOME to its internal location before it initialises its embedded Python interpreter so as to avoid conflicts with the parent process environment. But that doesn't seem to be the case if you can break it like this. 


I can’t imagine it’s that rare of a need.

Also, I tried to work through this with no luck: Python from an external interpreter. It seems that something in 2018 completely breaks using an external interpreter that could, for example, use virtualenvs to manage dependencies (this did work as recently as 2016).

Thanks in advance,

Joe

--
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/0e7033ed-58d2-487b-accd-7c5e29138483%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joe Weidenbach

unread,
Sep 1, 2018, 8:41:20 PM9/1/18
to python_in...@googlegroups.com
It's interesting, mayapy is an executable on windows as compared to the script version that comes with linux and OSX.  This seems to cause no end of issues, which is strange because usually windows apps are able to avoid clashes with the system by bundling libraries locally.

Setting that variable in Maya.env seems to be ignored entirely, as well.  

That said, I just tried removing PYTHONHOME from my env so I could query maya on what it expects (that caused a new error with PYTHONHOME pointing to one of my user directories, so I'm guessing chocolatey's doing something funny with the install).  When I added the PYTHONHOME var again, pointing to my default python, maya just started working again.  Very strange.

Joe Weidenbach

unread,
Sep 1, 2018, 9:27:36 PM9/1/18
to python_in...@googlegroups.com

I should clarify, PYTHONHOME in Maya.env is ignored. PYTHONPATH sets just fine.

Setting the PYTHONPATH in Maya.env gets past the module error, but then maya can’t find the DLL’s to actually do anything with those modules. It seems that PYTHONHOME does nasty things for maya.

I’ve been able to work around it by setting up a batch script that unsets PYTHONHOME and then runs maya, as suggested here. Bit of a hack, but it works.

Reply all
Reply to author
Forward
0 new messages