[ python-Bugs-713601 ] site.py breaks if prefix is empty

SourceForge.net noreply at sourceforge.net
Mon Aug 9 22:47:47 CEST 2004


Bugs item #713601, was opened at 2003-04-01 15:40
Message generated for change (Comment added) made by bcannon
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=713601&group_id=5470

Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Lalo Martins (lalo)
>Assigned to: Nobody/Anonymous (nobody)
Summary: site.py breaks if prefix is empty

Initial Comment:
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.

----------------------------------------------------------------------

>Comment By: Brett Cannon (bcannon)
Date: 2004-08-09 13:47

Message:
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.

----------------------------------------------------------------------

Comment By: Daniel Goertzen (goertzen)
Date: 2004-08-09 08:03

Message:
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.


----------------------------------------------------------------------

Comment By: Brett Cannon (bcannon)
Date: 2004-08-07 14:39

Message:
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?

----------------------------------------------------------------------

Comment By: Brett Cannon (bcannon)
Date: 2004-08-07 12:58

Message:
Logged In: YES 
user_id=357491

The NameError problem has been fixed.

----------------------------------------------------------------------

Comment By: Daniel Goertzen (goertzen)
Date: 2004-04-08 12:09

Message:
Logged In: YES 
user_id=843814

See this patch:
931938	prefix and exec_prefix as root dir bug

----------------------------------------------------------------------

Comment By: Daniel Goertzen (goertzen)
Date: 2004-04-08 09:01

Message:
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.

----------------------------------------------------------------------

Comment By: Brett Cannon (bcannon)
Date: 2003-06-08 15:54

Message:
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?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=713601&group_id=5470


More information about the Python-bugs-list mailing list