Multiple python installations mix their sys.prefix

Discussion in 'Python' started by Tech Support Box, Jan 24, 2011.

  1. Hi there
    I have several versions of python2.4 installed:
    - the OS, rpm-installed one in /usr
    - Several other versions in /usr/local, installed with --prefix /usr/
    local/inst-shared/<version> --exec-prefix /usr/local/inst/<version>

    My problem is when starting one of the versions from /usr/local,
    sys.prefix is set as "/usr" instead of the compile-time setting "/usr/
    local/inst-shared/<version>" and as a result sys.path contains paths
    from /usr, which shouldn't be there.

    After strace-ing the pythons from /usr/local and the one from /usr, it
    seems that python determines sys.prefix by first looking for os.py in
    every path component of the interpreter executable and adding "/lib/
    python2.4/os.py" to it (i.e. stat()-ing for /usr/local/inst/<version>/
    bin/lib/python2.4/os.py, then /usr/local/inst/<version>/lib/python2.4/
    os.py and so on) and only after it doesn't find os.py in any one of
    those paths does it look at the compile-time PREFIX setting. When
    doing this, it finds /usr/lib/python2.4/os.py (which belongs to the
    python installed at /usr) and determines that sys.prefix is /usr,
    which is wrong.

    The only fix I could come up with is setting PYTHONHOME before running
    python (which should be set differently for every version, and won't
    work in scripts using a shebang line) or moving /usr/lib/python2.4 to
    a different location (which is plain ugly). Is there a better way to
    make python take its compile-time option of prefix and *not* try to
    guess at runtime where it should be?

    Thanks.
     
    Tech Support Box, Jan 24, 2011
    #1
    1. Advertising

  2. Hi,
    I have a web page through this page when I try to add a new user then users created successfully but when try resetting their password then I am getting errors?

    add New user successfully

    public static void AddUser(ADUser adUser)
    {
    // Local variables
    DirectoryEntry oDE = null;
    DirectoryEntry oDENewUser = null;
    DirectoryEntries oDEs = null;

    try
    {
    oDE = GetDirectoryEntry(GetADPath(PROD, adUser.UserType));

    // 1. Create user account
    oDEs = oDE.Children;
    oDENewUser = oDEs.Add("CN=" + adUser.UserName, "user");

    // 2. Set properties
    SetProperty(oDENewUser, "givenName", adUser.FirstName);
    SetProperty(oDENewUser, "sn", adUser.LastName);
    SetProperty(oDENewUser, "mail", adUser.Email);
    SetProperty(oDENewUser, "sAMAccountName", adUser.UserName);
    oDENewUser.CommitChanges();

    /// 4. Enable account
    EnableAccount(oDENewUser);

    // 3. Set password
    //SetPassword(oDENewUser, adUser.Password);
    SetPassword1(oDENewUser.Path, adUser.Password);
    oDENewUser.CommitChanges();

    oDENewUser.Close();
    oDE.Close();
    }
    catch (Exception ex)
    {
    throw ex;
    }
    }
    I have try the following 2 SetPassword methods but getting error.
    Method 1.
    internal static void SetPassword1(string path, string userPassword)
    {
    //Local variables
    DirectoryEntry usr = null;

    try
    {
    usr = new DirectoryEntry();
    usr.Path = path;
    usr.AuthenticationType = AuthenticationTypes.Secure;
    object ret = usr.Invoke("SetPassword", userPassword);
    usr.CommitChanges();
    usr.Close();
    }
    catch (Exception ex)
    {
    throw ex;
    }
    }
    The exception raised (Error Code 80072035: The server is unwilling to process the request)
    Method 2.
    internal static void SetPassword(DirectoryEntry de, string userPassword)
    {
    //Local variables
    //DirectoryEntry usr = null;
    string quotePwd;
    byte[] pwdBin;

    try
    {
    quotePwd = String.Format(@"""{0}""", userPassword);
    pwdBin = System.Text.Encoding.Unicode.GetBytes(quotePwd);
    de.Properties["unicodePwd"].Value = pwdBin;
    de.CommitChanges();
    //usr.Close();
    }
    catch (Exception ex)
    {
    throw ex;
    }
    }
    The exception raised ("Exception has been thrown by the target of an invocation.")
    Is there an easy way to tell if there is a problem with changing a password?
    Please reply me as soon as possible.
    Thanks.


    Submitted via EggHeadCafe
    JSONP AJAX and ASP.NET Demystified
    http://www.eggheadcafe.com/tutorial...b83e65/jsonp-ajax-and-aspnet-demystified.aspx
     
    shrikant kesharwani, Jan 24, 2011
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tim Tyler
    Replies:
    36
    Views:
    1,494
    Darryl L. Pierce
    Dec 10, 2004
  2. Holger Joukl
    Replies:
    1
    Views:
    461
    Michael Hudson
    Feb 19, 2004
  3. Chris  Chiasson
    Replies:
    6
    Views:
    634
    Richard Tobin
    Nov 14, 2006
  4. Xavier Lapointe Desjardins

    sys.path with multiple Python installations

    Xavier Lapointe Desjardins, Mar 5, 2009, in forum: Python
    Replies:
    0
    Views:
    335
    Xavier Lapointe Desjardins
    Mar 5, 2009
  5. Python sys.prefix

    , Jan 21, 2010, in forum: Python
    Replies:
    0
    Views:
    605
Loading...

Share This Page