Get the directory of package

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
  09 September 2013
Get the directory of package

Hi everybody
I wonder if we can get the path to a package inside Maya? Like Os, or an user package which had been putted inside Maya's script folder?

  09 September 2013
The easiest solution would be to import the module and then print the __file__ method.


import maya
import os
import your_custom_module

print maya.__file__
print os.__file__
print your_custom_module.__file__
  09 September 2013
Are you trying to find the path of an active module, or the paths where modules may lie? Are you trying to find the path interactively in Maya or as part of your code?

Depending on what you need it for, you can look into python's inspect module:

-- particularly, look into inspect.getfile() and inspect.currentframe() if you are trying to determine the source of your code at runtime.

If you are trying to access modules in subfolders, you can add a file inside the subfolder to access it as a module:

If you're just looking for paths that Maya will look for python scripts, the sys module will help:
import sys
for p in sys.path:
       print p
  09 September 2013
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 11:07 AM.

Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.