473,418 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

what is Python's module search path?

I need a little help here.

I'm developing some introductory material on Python for non-programmers.

The first draft includes this statement. Is this correct?

-----------------------------------------------------------------
When loading modules, Python looks for modules
in the following places in the following order:

* Python's built-in modules, including modules in the standard library
* in the /python23/Libs/site-packages directory
* the directory from which your main module was loaded
* in directories in PYTHONPATH

------------------------------------------------------------------
Thanks in advance! -- Steve Ferg
Jul 18 '05 #1
3 9679
Stephen Ferg:
I need a little help here.


See "6.1.1 The Module Search Path" on
http://www.python.org/doc/current/tut/node8.html

--
René Pijlman
Jul 18 '05 #2
Thanks.

It says """When a module named spam is imported, the interpreter
searches for a file named spam.py in the current directory, and then
in the list of directories specified by the environment variable
PYTHONPATH. ... When PYTHONPATH is not set, or when the file is not
found there, the search continues in an installation-dependent default
path; on Unix, this is usually .:/usr/local/lib/python.

Actually, modules are searched in the list of directories given by the
variable sys.path which is initialized from the directory containing
the input script (or the current directory), PYTHONPATH and the
installation-dependent default."""

Is the installation-dependent default path on Windows usually
Lib/site-packages?

If so, then it looks like my original search order was wrong,
and the correct search order (on Windows) is:

---------------------------------------------------------
* Python's built-in modules, including modules in the standard
library
* the directory from which your main module was loaded
* in directories in PYTHONPATH
* in the /python23/Libs/site-packages directory
--------------------------------------------------------

Is that correct?

Part of what is confusing me is that Lib/site-packages is pretty
poorly documented.
Jul 18 '05 #3
Stephen Ferg:
It says """When a module named spam is imported, the interpreter
searches for a file named spam.py in the current directory, and then
in the list of directories specified by the environment variable
PYTHONPATH. ... When PYTHONPATH is not set, or when the file is not
found there, the search continues in an installation-dependent default
path; on Unix, this is usually .:/usr/local/lib/python.

Actually, modules are searched in the list of directories given by the
variable sys.path which is initialized from the directory containing
the input script (or the current directory), PYTHONPATH and the
installation-dependent default."""

Is the installation-dependent default path on Windows usually
Lib/site-packages?
I guess it's more than that.

PythonWin 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on
win32.
import sys
print sys.path

['','C:\\Python\\Python22\\lib\\site-packages\\Pythonwin',
'C:\\Python\\Python22\\lib\\site-packages\\win32',
'C:\\Python\\Python22\\lib\\site-packages\\win32\\lib',
'C:\\Python\\Python22\\lib\\site-packages', 'C:\\Python\\Python22\\DLLs',
'C:\\Python\\Python22\\lib', 'C:\\Python\\Python22\\lib\\lib-tk',
'C:\\Python\\Python22']

None of these directories qualify for any of the other categories, so
these must all be in the installation-dependent default.
If so, then it looks like my original search order was wrong,
and the correct search order (on Windows) is:

---------------------------------------------------------
* Python's built-in modules, including modules in the standard
library
* the directory from which your main module was loaded
* in directories in PYTHONPATH
* in the /python23/Libs/site-packages directory
--------------------------------------------------------

Is that correct?
Well no, I don't think so. The tutorial doesn't say that the modules in
the standard library are searched first. It says the current directory is
first, which you don't even mention. And the tutorial says sys.path is
searched, which may be modified by the program.

Why are you trying to rephrase the tutorial, when the tutorial is
perfectly clear?
Part of what is confusing me is that Lib/site-packages is pretty
poorly documented.


It doesn't have to be, for ordinary users. My guess is the documentation
is in this area: http://www.python.org/sigs/distutils-sig/doc/

--
René Pijlman
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Peter Schwalm | last post by:
I'd like to modify the python search path depending on the source directory of the script being started. The reason is: I use a version control system, and the python scripts and modules are...
10
by: Andrew Dalke | last post by:
Is there an author index for the new version of the Python cookbook? As a contributor I got my comp version delivered today and my ego wanted some gratification. I couldn't find my entries. ...
10
by: TokiDoki | last post by:
Hello there, I have been programming python for a little while, now. But as I am beginning to do more complex stuff, I am running into small organization problems. It is possible that what I...
28
by: Jay | last post by:
OK, I have this XML doc, i dont know much about XML, but what i want to do is take certain parts of the XML doc, such as </title> blah </title> and take just that and put onto a text doc. Then...
0
by: nojhan | last post by:
I'm trying to embbed the python interpreter as a class attribute, initializing it in the constructor, and finalizing in destructor. The code is rather simple: // base_path is an attribute of...
1
by: aznach | last post by:
Hello! I have a shared hosting account at GrokThis.net and have a problem with the module order of the Python search path. I'd like to use django's svn trunk instead of the...
0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 342 open (-38) / 3712 closed (+54) / 4054 total (+16) Bugs : 951 open (-14) / 6588 closed (+33) / 7539 total (+19) RFE : 257 open...
3
by: david | last post by:
You learn something new every day: On my ubuntu, update-manager is supposed to use the python2.5 installed on /usr/bin. Well, I had subsequently installed a whole bunch of stuff in /usr/local...
7
by: Anita Kean | last post by:
Hello I just downloaded the new python2.6 documentation, full of hopes it would solve some basic mysteries for me. I'm new to python, so please forgive my ignorance. I've two questions. 1)...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.