By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,885 Members | 1,499 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,885 IT Pros & Developers. It's quick & easy.

Is there some Python function that searches "sys.path" for a module?

P: n/a
Python's own loader searches "sys.path" for module names, but is there
some function that makes that search functionality accessible to
Python programs? I need the absolute pathname of a module, with the
search being done exactly the same way "import" does it. The loader for
"egg" files has this functionality, but I'd like to find out if there's
a standard way to do this before looking into that source code.

Also, it seems that the environment variable "PYTHONPATH" applies to
"import", but not to the starting module named on the Python command
line. Is that correct? Thanks.

John Nagle
Jan 15 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hello John,
* *Python's own loader searches "sys.path" for module names, but is there
some function that makes that search functionality accessible to
Python programs? *I need the absolute pathname of a module, with the
search being done exactly the same way "import" does it. *The loader for
"egg" files has this functionality, but I'd like to find out if there's
a standard way to do this before looking into that source code.

* *Also, it seems that the environment variable "PYTHONPATH" applies to
"import", but not to the starting module named on the Python command
line. *Is that correct? *Thanks.
http://docs.python.org/lib/module-imp.html

HTH,
--
Miki Tebeka <mi*********@gmail.com>
http://pythonwise.blogspot.com
Jan 15 '08 #2

P: n/a
If I understand you correctly, you want this:

module.__file__


John Nagle wrote:
Python's own loader searches "sys.path" for module names, but is there
some function that makes that search functionality accessible to
Python programs? I need the absolute pathname of a module, with the
search being done exactly the same way "import" does it. The loader for
"egg" files has this functionality, but I'd like to find out if there's
a standard way to do this before looking into that source code.

Also, it seems that the environment variable "PYTHONPATH" applies to
"import", but not to the starting module named on the Python command
line. Is that correct? Thanks.

John Nagle

--
Shane Geiger
IT Director
National Council on Economic Education
sg*****@ncee.net | 402-438-8958 | http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy

Jan 15 '08 #3

P: n/a
Miki wrote:
http://docs.python.org/lib/module-imp.html
Ah. "imp.find_module". I was looking in "sys" and
path-related places. Thanks.

John Nagle
Jan 15 '08 #4

P: n/a
Shane Geiger wrote:
If I understand you correctly, you want this:

module.__file__
No, this is for a module that isn't loaded, and
I don't want to load it. What I needed was "imp.find_module()".
I don't want to load the module in the current Python instance.
I need its path so I can start it in a subprocess.

John Nagle
Jan 15 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.