Python system path

37 views
Skip to first unread message

jettam

unread,
Oct 16, 2017, 4:44:50 PM10/16/17
to Python Programming for Autodesk Maya

 At the moment if I add a path to my Maya.env   I only get to read the give path, not all its sub-folders too? 

PYTHONPATH = E:\ProfessionalDevelopment\python\Introduction to Python Scripting in Maya\cgcircuitPython\;
E:\ProfessionalDevelopment\python\Introduction to Python Scripting in Maya\cgcircuitPython\.     # I thought adding a . here would be saying from here and everything below. It didn't work.


Also. Once I have updated the Maya.env how can I get Maya to reload it. Currently I have to restart Maya ? 

Justin Israel

unread,
Oct 16, 2017, 6:15:53 PM10/16/17
to python_in...@googlegroups.com
On Tue, Oct 17, 2017 at 9:44 AM jettam <justin...@gmail.com> wrote:

 At the moment if I add a path to my Maya.env   I only get to read the give path, not all its sub-folders too? 

That is how the PYTHONPATH and import mechanism work in Python. You add a path and it makes packages/modules accessible below that point, with their namespaces rooted to the PYTHONPATH. Example:

PYTHONPATH=myRootPath

myRootPath/
    |- foo
    |- foo2
        |- bar
            |- baz

Then you can do the following imports:

import foo
import foo2
import foo2.bar.baz
from foo2.bar import baz
 

PYTHONPATH = E:\ProfessionalDevelopment\python\Introduction to Python Scripting in Maya\cgcircuitPython\;
E:\ProfessionalDevelopment\python\Introduction to Python Scripting in Maya\cgcircuitPython\.     # I thought adding a . here would be saying from here and everything below. It didn't work.

Not sure where you found information suggesting this would work the way you thought.
 


Also. Once I have updated the Maya.env how can I get Maya to reload it. Currently I have to restart Maya ? 

Yes, the Maya.env gets read when Maya starts up. If you change it, you need to restart Maya.

What is your intended workflow that you are trying to solve? What kind of imports are you trying to access that require some kind of recursive appending to the PYTHONPATH? Can you make use of the namespaced imports like I suggested earlier, to access nested packages?

If you are trying to dynamically update the PYTHONPATH within a running Maya session, then you would need to update the values of sys.path

import sys
print sys.path
 

--
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/2cf1397b-f276-44e8-86d6-e8553da74191%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jettam

unread,
Oct 16, 2017, 7:52:25 PM10/16/17
to Python Programming for Autodesk Maya
Your reply suggest I should be able to do it "That is how the PYTHONPATH and import mechanism work in Python. You add a path and it makes packages/modules accessible below that point"

But I can't make it read a module that is found deeper in another folder. even after a restart.

For example if I was to assign this path to my Maya.env 
E:\ProfessionalDevelopment\python\Introduction_to_Python_Scripting_in_Maya\

I would want to be able to access a module found here.
E:\ProfessionalDevelopment\python\Introduction_to_Python_Scripting_in_Maya\week6_v003\homeWork\wk6_module.py



To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

Justin Israel

unread,
Oct 16, 2017, 7:56:12 PM10/16/17
to python_in...@googlegroups.com
On Tue, Oct 17, 2017 at 12:52 PM jettam <justin...@gmail.com> wrote:
Your reply suggest I should be able to do it "That is how the PYTHONPATH and import mechanism work in Python. You add a path and it makes packages/modules accessible below that point"

But I can't make it read a module that is found deeper in another folder. even after a restart.

My reply was probably not clear enough. I was saying the bebaviour that you are seeing is exactly how it works, as opposed to the behaviour you expect to see. 


For example if I was to assign this path to my Maya.env 
E:\ProfessionalDevelopment\python\Introduction_to_Python_Scripting_in_Maya\

I would want to be able to access a module found here.
E:\ProfessionalDevelopment\python\Introduction_to_Python_Scripting_in_Maya\week6_v003\homeWork\wk6_module.py

Yes, according to my examples from the last reply, you would need to access this module by the module namespaces:

from  week6_v003.homeWork import wk6_module

Or some variation of the import statement, using the namespaces. This also assumes that you have an __init__.py file located within each of those sub-directories.

To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
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/02585df1-326d-4f75-a3ab-4f602096bc40%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages