setting PYTHONPATH to override system wide site-packages

Discussion in 'Python' started by per, Mar 1, 2009.

  1. per

    per Guest

    hi all,

    i recently installed a new version of a package using python setup.py
    install --prefix=/my/homedir on a system where i don't have root
    access. the old package still resides in /usr/lib/python2.5/site-
    packages/ and i cannot erase it.

    i set my python path as follows in ~/.cshrc

    setenv PYTHONPATH /path/to/newpackage

    but whenever i go to python and import the module, the version in site-
    packages is loaded. how can i override this setting and make it so
    python loads the version of the package that's in my home dir?

    thanks.
     
    per, Mar 1, 2009
    #1
    1. Advertising

  2. per

    Carl Banks Guest

    On Feb 28, 7:30 pm, per <> wrote:
    > hi all,
    >
    > i recently installed a new version of a package using python setup.py
    > install --prefix=/my/homedir on a system where i don't have root
    > access. the old package still resides in /usr/lib/python2.5/site-
    > packages/ and i cannot erase it.
    >
    > i set my python path as follows in ~/.cshrc
    >
    > setenv PYTHONPATH /path/to/newpackage
    >
    > but whenever i go to python and import the module, the version in site-
    > packages is loaded. how can i override this setting and make it so
    > python loads the version of the package that's in my home dir?



    What happens when you run the command "print sys.path" from the Python
    prompt? /path/to/newpackage should be the second item, and shoud be
    listed in front of the site-packages dir.

    What happens when you run "print os.eviron['PYTHONPATH']" at the
    Python interpreter? It's possible that the sysadmin installed a
    script that removes PYTHONPATH environment variable before invoking
    Python. What happens when you type "which python" at the csh prompt?

    What happens when you type "ls /path/to/newpackage" at your csh
    prompt? Is the module you're trying to import there?

    You approach should work. These are just suggestions on how to
    diagnose the problem; we can't really help you figure out what's wrong
    without more information.


    Carl Banks
     
    Carl Banks, Mar 1, 2009
    #2
    1. Advertising

  3. per

    per Guest

    On Feb 28, 11:24 pm, Carl Banks <> wrote:
    > On Feb 28, 7:30 pm, per <> wrote:
    >
    > > hi all,

    >
    > > i recently installed a new version of a package using python setup.py
    > > install --prefix=/my/homedir on a system where i don't have root
    > > access. the old package still resides in /usr/lib/python2.5/site-
    > > packages/ and i cannot erase it.

    >
    > > i set my python path as follows in ~/.cshrc

    >
    > > setenv PYTHONPATH /path/to/newpackage

    >
    > > but whenever i go to python and import the module, the version in site-
    > > packages is loaded. how can i override this setting and make it so
    > > python loads the version of the package that's in my home dir?

    >
    > What happens when you run the command "print sys.path" from the Python
    > prompt?  /path/to/newpackage should be the second item, and shoud be
    > listed in front of the site-packages dir.
    >
    > What happens when you run "print os.eviron['PYTHONPATH']" at the
    > Python interpreter?  It's possible that the sysadmin installed a
    > script that removes PYTHONPATH environment variable before invoking
    > Python.  What happens when you type "which python" at the csh prompt?
    >
    > What happens when you type "ls /path/to/newpackage" at your csh
    > prompt?  Is the module you're trying to import there?
    >
    > You approach should work.  These are just suggestions on how to
    > diagnose the problem; we can't really help you figure out what's wrong
    > without more information.
    >
    > Carl Banks


    hi,

    i am setting it programmatically now, using:

    import sys
    sys.path = [....]

    sys.path now looks exactly like what it looked like before, except the
    second element is my directory. yet when i do

    import mymodule
    print mymodule.__version__

    i still get the old version...

    any other ideas?
     
    per, Mar 1, 2009
    #3
  4. per

    per Guest

    On Feb 28, 11:53 pm, per <> wrote:
    > On Feb 28, 11:24 pm, Carl Banks <> wrote:
    >
    >
    >
    > > On Feb 28, 7:30 pm, per <> wrote:

    >
    > > > hi all,

    >
    > > > i recently installed a new version of a package using python setup.py
    > > > install --prefix=/my/homedir on a system where i don't have root
    > > > access. the old package still resides in /usr/lib/python2.5/site-
    > > > packages/ and i cannot erase it.

    >
    > > > i set my python path as follows in ~/.cshrc

    >
    > > > setenv PYTHONPATH /path/to/newpackage

    >
    > > > but whenever i go to python and import the module, the version in site-
    > > > packages is loaded. how can i override this setting and make it so
    > > > python loads the version of the package that's in my home dir?

    >
    > > What happens when you run the command "print sys.path" from the Python
    > > prompt?  /path/to/newpackage should be the second item, and shoud be
    > > listed in front of the site-packages dir.

    >
    > > What happens when you run "print os.eviron['PYTHONPATH']" at the
    > > Python interpreter?  It's possible that the sysadmin installed a
    > > script that removes PYTHONPATH environment variable before invoking
    > > Python.  What happens when you type "which python" at the csh prompt?

    >
    > > What happens when you type "ls /path/to/newpackage" at your csh
    > > prompt?  Is the module you're trying to import there?

    >
    > > You approach should work.  These are just suggestions on how to
    > > diagnose the problem; we can't really help you figure out what's wrong
    > > without more information.

    >
    > > Carl Banks

    >
    > hi,
    >
    > i am setting it programmatically now, using:
    >
    > import sys
    > sys.path = [....]
    >
    > sys.path now looks exactly like what it looked like before, except the
    > second element is my directory. yet when i do
    >
    > import mymodule
    > print mymodule.__version__
    >
    > i still get the old version...
    >
    > any other ideas?


    in case it helps, it gives me this warning when i try to import the
    module

    /usr/lib64/python2.5/site-packages/pytz/__init__.py:29: UserWarning:
    Module dateutil was already imported from /usr/lib64/python2.5/site-
    packages/dateutil/__init__.pyc, but /usr/lib/python2.5/site-packages
    is being added to sys.path
    from pkg_resources import resource_stream
     
    per, Mar 1, 2009
    #4
  5. per

    Carl Banks Guest

    On Feb 28, 9:18 pm, per <> wrote:
    > On Feb 28, 11:53 pm, per <> wrote:
    >
    >
    >
    > > On Feb 28, 11:24 pm, Carl Banks <> wrote:

    >
    > > > On Feb 28, 7:30 pm, per <> wrote:

    >
    > > > > hi all,

    >
    > > > > i recently installed a new version of a package using python setup.py
    > > > > install --prefix=/my/homedir on a system where i don't have root
    > > > > access. the old package still resides in /usr/lib/python2.5/site-
    > > > > packages/ and i cannot erase it.

    >
    > > > > i set my python path as follows in ~/.cshrc

    >
    > > > > setenv PYTHONPATH /path/to/newpackage

    >
    > > > > but whenever i go to python and import the module, the version in site-
    > > > > packages is loaded. how can i override this setting and make it so
    > > > > python loads the version of the package that's in my home dir?

    >
    > > > What happens when you run the command "print sys.path" from the Python
    > > > prompt?  /path/to/newpackage should be the second item, and shoud be
    > > > listed in front of the site-packages dir.

    >
    > > > What happens when you run "print os.eviron['PYTHONPATH']" at the
    > > > Python interpreter?  It's possible that the sysadmin installed a
    > > > script that removes PYTHONPATH environment variable before invoking
    > > > Python.  What happens when you type "which python" at the csh prompt?

    >
    > > > What happens when you type "ls /path/to/newpackage" at your csh
    > > > prompt?  Is the module you're trying to import there?

    >
    > > > You approach should work.  These are just suggestions on how to
    > > > diagnose the problem; we can't really help you figure out what's wrong
    > > > without more information.

    >
    > > > Carl Banks

    >
    > > hi,

    >
    > > i am setting it programmatically now, using:

    >
    > > import sys
    > > sys.path = [....]

    >
    > > sys.path now looks exactly like what it looked like before, except the
    > > second element is my directory. yet when i do

    >
    > > import mymodule
    > > print mymodule.__version__

    >
    > > i still get the old version...

    >
    > > any other ideas?

    >
    > in case it helps, it gives me this warning when i try to import the
    > module
    >
    > /usr/lib64/python2.5/site-packages/pytz/__init__.py:29: UserWarning:
    > Module dateutil was already imported from /usr/lib64/python2.5/site-
    > packages/dateutil/__init__.pyc, but /usr/lib/python2.5/site-packages
    > is being added to sys.path
    >   from pkg_resources import resource_stream


    Ok then. When pkg_resources is involved, who knows what behavior to
    expect.

    pkg_resources.py is a third-party module from PEAK (which
    unfortunately a number of other third-party packages depend on, so it
    can be hard to keep your installation free of it, but I digress).
    Among other things no one knows about, it's a sort of run-time package
    version management system. It's possible, maybe, that some module
    that runs on startup specifically requested and imported the version
    of dateutils that's on the system path. Which means, if you don't
    properly appease pkg_resources, it could actually ignore your version
    of the package even if it's earlier in the system path. This is only
    speculation, because who actually knows what's in the mind of
    pkg_resources?, but if that is the reason, I won't be the one to tell
    you how to fix it.

    Here's something to try, however. Set up your PYTHONPATH as you did
    before, but also create an empty pkg_resources.py file in the
    directory you specified. Warning: this might make some packages
    unusable.


    Not-a-fan-of-pkg_resources-ly y'rs,

    Carl Banks
     
    Carl Banks, Mar 1, 2009
    #5
    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. Web Developer

    char 8bit wide or 7bit wide in c++?

    Web Developer, Jul 31, 2003, in forum: C++
    Replies:
    2
    Views:
    620
    John Harrison
    Jul 31, 2003
  2. Disc Magnet
    Replies:
    2
    Views:
    741
    Jukka K. Korpela
    May 15, 2010
  3. Disc Magnet
    Replies:
    2
    Views:
    822
    Neredbojias
    May 14, 2010
  4. Hemant Shah

    setting system wide value for SYSTEM_FD_MAX

    Hemant Shah, Apr 15, 2004, in forum: Perl Misc
    Replies:
    0
    Views:
    143
    Hemant Shah
    Apr 15, 2004
  5. Martin Rinehart

    80 columns wide? 132 columns wide?

    Martin Rinehart, Oct 31, 2008, in forum: Javascript
    Replies:
    16
    Views:
    195
    John W Kennedy
    Nov 13, 2008
Loading...

Share This Page