So... This was the 2nd week and I was stubborn to understand how the Maya environment variables work and spent hours reading online (here, here, and here). My goal to understand Maya environment variables was to simply open Maya anytime and run my script and it should work. Also, I wanted to keep my codes in the Maya project, along with rig, model and textures (not in the Maya's default location for scripts). I had a really hard time understanding it completely and when I read the word PYTHONPATH, I felt like we have met before because once upon a time, I had set the PYTHONPATH inside Visual Studio Code (IDE) and then I added MAYA_SCRIPT_PATH inside Maya.env file. When I executed MEL command -
getenv "MAYA_SCRIPT_PATH";
I could see my desired path in the output but still my script was not working and showing the error "No module named *****". Then I added the environment variables in "My Computer > Properties > Advanced System Settings > Environment Variables" and followed the steps mentioned here ; and it worked!
[Note: If you are using operating system other than Windows, you will have to follow some other minor changes, as mentioned in the links above.]
Then I deleted the locations from MAYA_SCRIPT_PATH inside Maya.env file and it still works because of the PYTHONPATH. I don't think this is how it should work but it works for now and I want to move ahead with my project. The issue with this is that I will be having a hard time if I want my code to be executed in other system, I guess. Also, I had to add the locations very specifically, for example- my directory structure looks like this-
So, I had to add 5 locations in my PYTHONPATH i.e. FrankRig, rigLib, base, rig, utils, even though the __init__.py had imported the other directory. Maybe I am doing something wrong.
Later, while following the tutorial I am starting with, I found that I could have done something else for a temporary fix-
import sys
for p in sys:
print(p)
rigDir = 'C:\Users\...\code\python\FrankRig'
if not rigDir in sys.path:
sys.path.append(rigDir)
To fix it permanently, as suggested in tutorial - Procedural rigging with python , all I needed to do was to edit the Maya.env file and add below lines of code-
PYTHONPATH = 'C:\Users\...\code\python\FrankRig'
But it did not work for me in Maya 2020, maybe the tutorial is too old (2015). And I'm glad I can do it by simply adding it as I mentioned at the start of this post.
Things I covered this week is-
Setting the environment variables
Getting the IDE up and running, including the autocomplete for maya commands on Visual Studio Code
Set up the base directory structure for my code
Hoping to catch up for this week today!
Peace
Comentarios