On Tue, Oct 17, 2017 at 12:52 PM jettam <[email protected]> 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.


>
>
>
>
> On Monday, October 16, 2017 at 3:15:53 PM UTC-7, Justin Israel wrote:
>
>>
>>
>> On Tue, Oct 17, 2017 at 9:44 AM jettam <[email protected]> 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 [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/python_inside_maya/2cf1397b-f276-44e8-86d6-e8553da74191%40googlegroups.com
>>> <https://groups.google.com/d/msgid/python_inside_maya/2cf1397b-f276-44e8-86d6-e8553da74191%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/02585df1-326d-4f75-a3ab-4f602096bc40%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/02585df1-326d-4f75-a3ab-4f602096bc40%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1U2OBPv4N%3DgmZZhY9V%3DbgMgNwZ%3DqR4S9va_9c1EpBZeQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to