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.

installing pyMel for multiple users on 2024

installing pyMel for multiple users on 2024

bmagner888
Enthusiast Enthusiast
352 Views
1 Reply
Message 1 of 2

installing pyMel for multiple users on 2024

bmagner888
Enthusiast
Enthusiast

Autodesk chose not to include pyMel in the default  installation of Maya 2024, but my client studios have numerous automation tools that rely on pymel, and I want to create a script that users/artists can run from Maya to handle the installation without having to open the command prompt.

I'm aware that the provided instructions are seemingly simple, but if you have lots of artists with widely varying skill sets working remotely, this can be a huge headache.  I want to give them a single command or shelf button they can run from within maya, and give them a happy notice that it installed correctly and tell them to restart maya.
-----------------------------------------
from the Autodesk documentation:
https://help.autodesk.com/view/MAYAUL/2024/ENU/?guid=GUID-2AA5EFCE-53B1-46A0-8E43-4CD0B2C72FB4

  - To install PyMEL, change directory to where mayapy is installed, and then run pip install pymel
 - mayapy -m pip install pymel
  or:
 - mayapy -m pip install --user pymel
-----------------------------------------
to condense this into a python script, here is my methodology:

#Query installation directory in case artist installed on different drive or custom location

mayaLocation = mel.eval('getenv("MAYA_LOCATION")')
if not mayaLocation[-1]=='/':
    mayaLocation+='/'
mayapy_location = mayaLocation+'bin'
lst = mayapy_location.split('/')
drive = lst[0]
lst = lst[1:len(lst)]
mayapy_location = drive +'\\' +os.path.join(*lst)
#Result  = C:\Program Files\Autodesk\Maya2024\bin

 

cmd1 = "mayapy -m pip install pymel"
cmd2 = "mayapy -m pip install --user pymel"

import subprocess
try:
    subprocess.run(cmd1)
except:
    subprocess.run(cmd2)


Question: Will this work? I can't test it on my own machine because pymel is already installed. Do I need to include a "change directory" command to the subprocess prior to executing cmd1?

I tested this and it failed:
cmd = "cd " + mayapy_location
subprocess.run(cmd)

0 Likes
353 Views
1 Reply
Reply (1)
Message 2 of 2

lee.dunham
Collaborator
Collaborator
First off, I assume `subprocess.run(cmd)` could fail as Program Files has a space in it.
Put the path in double quotes in the string to ensure its passed to the subprocess as a single string.

I also think you can more easily get mayapy using `sys.executable`.

To test, you could also create a virtual environment with bare minimum, and set the Maya environment to use the virtual env instead.

If this is for clients, you could provide a range of tools/scripts to deal with this (.bat, startup, etc) and perhaps add a `onMayaDroppedPythonFile` function to it to allow them to drag and drop in install.
0 Likes