How to setup custome script directory

How to setup custome script directory

Phil.Newm
Explorer Explorer
606 Views
4 Replies
Message 1 of 5

How to setup custome script directory

Phil.Newm
Explorer
Explorer

Hello, hello,

I'm currently working on some python tools for Maya 2022 on Linux and I'd like to import my .py files from a custom directory on my system. So after reading through Maya's help page on build environments I added those Environment Variables to my Maya.env for Maya 2022.

So I expected "MAYA_SCRIPT_PATH" to include a custom path to load scripts from this location when just typing import [script name] in Maya's script editor.v Later I found out about "USER_SCRIPT_PATH" as well. But I still don't know the difference.
But sadly it doesn't work even though I'm able to see the paths correctly added when I execute
<getenv MAYA_SCRIPT_PATH> as MEL command

 

So again my goal is to just type <import [script name]> into the python script editor and Maya should know about any additional folders to search for scripts and load it.

 

Would definitely appreciate some help with this.

So thanks for reading through and have a great day 🙂

 

0 Likes
Accepted solutions (2)
607 Views
4 Replies
Replies (4)
Message 2 of 5

Kahylan
Advisor
Advisor
Accepted solution

Hi!

 

To add a custom path to your python path, you just need to run the following command from a python tab in the scripteditor:

import sys
sys.path.append('/Path/Where/Your/Folder/Is/Located')

 

This should automatically add your path to the PYTHON_PATH, given the correct path is provided.

 

I hope it helps!

Message 3 of 5

Phil.Newm
Explorer
Explorer

Okay thank you that worked!

Message 4 of 5

Kahylan
Advisor
Advisor

No problem, happy to help 🙂

0 Likes
Message 5 of 5

Phil.Newm
Explorer
Explorer
Accepted solution

Just to add this bit

I ended up with adding 

PYTHONPATH=/path/to/scripts/folder/

to my Maya.env since that worked as well.

I'm just not to sure if that's a reliable way or not. I'll probably find that out in the next time.

0 Likes