This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: site.py breaks if prefix is empty
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, georg.brandl, goertzen, lalo
Priority: normal Keywords:

Created on 2003-04-01 23:40 by lalo, last changed 2022-04-10 16:08 by admin. This issue is now closed.

Messages (10)
msg15350 - (view) Author: Lalo Martins (lalo) Date: 2003-04-01 23:40
verified in 2.3a1 and 2.2.2:

prefixes = [sys.prefix]
if sys.exec_prefix != sys.prefix:
    prefixes.append(sys.exec_prefix)
for prefix in prefixes:
    if prefix:
        # do stuff - in particular, define the
"sitedir" variable
        # and add site-packages to the path
del prefix, sitedir

if sys.prefix == sys.exec_prefix and both are empty
(which is the case if you compile with --prefix=/ as
for the
Gnu OS for example), this will have two unfortunate
results:

1. site-packages will not be added to the path.

2. site.py will abort with a NameError (it tries to del
sitedir
which isn't defined)

The fix seems to be as simple as removing the "if prefix"
line.  From mailing list archives, it seems to have been
added to cope with unusual loading environments related
to windows and COM - in this case, there is probably a
safer way to check for this condition.  If the prefix is
empty, this just means it's the root, and no further
assumptions should be made.
msg15351 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2003-06-08 22:54
Logged In: YES 
user_id=357491

Why is sys.prefix == '' if it is set to '/' as the command-line 
argument?  Checking Modules/getpath.c there appears a few 
places where things could go awry if an enviroment variable is 
set that causes the code to think it has already found the 
location before it reaches what the Makefile set PREFIX and 
EXEC_PREFIX to.  The steps used are in the initial comment of 
the file.  Any of those a possible reason for your problem?
msg15352 - (view) Author: Daniel Goertzen (goertzen) Date: 2004-04-08 16:01
Logged In: YES 
user_id=843814

Just ran into the same problem when I configure with --prefix=/

The problem is in getpath.c.  Before trying to find your
lib/python dir based on what you submitted in configure, it
performs a search based on the python execution path
(probably /bin).  It keeps chopping the path down with the
reduce() function and then adds "/lib/python" and sees if a
landmark file is there.  The problem is that reduce() will
freely chop away the last / leaving your prefix as a null
string.

I'm going to try tweaking reduce() so it doesn't hack off
the last / if its the last one.
msg15353 - (view) Author: Daniel Goertzen (goertzen) Date: 2004-04-08 19:09
Logged In: YES 
user_id=843814

See this patch:
931938	prefix and exec_prefix as root dir bug
msg15354 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2004-08-07 19:58
Logged In: YES 
user_id=357491

The NameError problem has been fixed.
msg15355 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2004-08-07 21:39
Logged In: YES 
user_id=357491

I just tried compiling on the 2.3 maintenance branch with --prefix=/ and 
I had sys.prefix be set to '/'.  Can you check to see if you are still having 
sys.prefix set to an empty string?
msg15356 - (view) Author: Daniel Goertzen (goertzen) Date: 2004-08-09 15:03
Logged In: YES 
user_id=843814

Not too sure what you mean by maintenance branch, but 2.3.4
and today's CVS python/dist/src tree still produced an empty
string for sys.prefix when configured with --prefix=/

FYI, I install my root pefix python into a separate
directory by running "make install prefix=mydir".  "mydir"
is the root filesystem for an embedded device that we make.
 For testing, I chroot to mydir and can run python.  The
overall procedure is:

./configure --prefix=/
make
make install prefix=mydir
chroot mydir
python

I don't think the install and chroot shenanigans make any
difference, but I thought I'd mention it in case I'm doing
something dumb.
msg15357 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2004-08-09 20:47
Logged In: YES 
user_id=357491

The 2.3 maintenance branch is the CVS version of the 2.3 tree.  But if 
you tried this against 2.3.4 chances are that is close enough.

Unfortunately under OS X I get '/' for sys.prefix and not an empty string 
so I can't debug this.
msg15358 - (view) Author: Daniel Goertzen (goertzen) Date: 2004-08-09 21:38
Logged In: YES 
user_id=843814

Refer to patch 931938.  Incidentally someone else just
complained that I forgot to actually upload the file, so I
just put it there today.  

The patch fixes the prefix search as described in step 3 in
the comments of getpath.c.  Looking at the code that the
patch fixes, it should be pretty easy to see how the
reduce() function can chop the path down to an empty string
when prefix and exec_prefix are the root directory.
msg15359 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-02-20 17:38
Logged In: YES 
user_id=849994

Fixed in rev. 42522, 42523.
History
Date User Action Args
2022-04-10 16:08:00adminsetgithub: 38252
2003-04-01 23:40:38lalocreate