Go Back   Velocity Reviews > Newsgroups > Python
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

Python - setting PYTHONPATH to override system wide site-packages

 
Thread Tools Search this Thread
Old 03-01-2009, 03:30 AM   #1
Default setting PYTHONPATH to override system wide site-packages


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
  Reply With Quote
Old 03-01-2009, 04:24 AM   #2
Carl Banks
 
Posts: n/a
Default Re: setting PYTHONPATH to override system wide site-packages
On Feb 28, 7:30*pm, per <perfr...@gmail.com> 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
  Reply With Quote
Old 03-01-2009, 04:53 AM   #3
per
 
Posts: n/a
Default Re: setting PYTHONPATH to override system wide site-packages
On Feb 28, 11:24*pm, Carl Banks <pavlovevide...@gmail.com> wrote:
> On Feb 28, 7:30*pm, per <perfr...@gmail.com> 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
  Reply With Quote
Old 03-01-2009, 05:18 AM   #4
per
 
Posts: n/a
Default Re: setting PYTHONPATH to override system wide site-packages
On Feb 28, 11:53*pm, per <perfr...@gmail.com> wrote:
> On Feb 28, 11:24*pm, Carl Banks <pavlovevide...@gmail.com> wrote:
>
>
>
> > On Feb 28, 7:30*pm, per <perfr...@gmail.com> 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
  Reply With Quote
Old 03-01-2009, 06:52 AM   #5
Carl Banks
 
Posts: n/a
Default Re: setting PYTHONPATH to override system wide site-packages
On Feb 28, 9:18*pm, per <perfr...@gmail.com> wrote:
> On Feb 28, 11:53*pm, per <perfr...@gmail.com> wrote:
>
>
>
> > On Feb 28, 11:24*pm, Carl Banks <pavlovevide...@gmail.com> wrote:

>
> > > On Feb 28, 7:30*pm, per <perfr...@gmail.com> 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
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Detecting Intruders on Your System Is Fun and Easy konanimo@gmail.com DVD Video 0 12-11-2007 01:52 PM
Judge: File-swapping tools are legal Citizen Bob DVD Video 140 11-08-2006 06:42 PM
Setting Up Your First Home Theater Surround System: Do's and Don'ts Silverstrand Front Page News 0 04-29-2006 03:12 AM
XP and security Pikoro A+ Certification 2 08-18-2003 05:09 AM
Re: 7. The truth about our creator. .7 john smith DVD Video 2 07-25-2003 03:54 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46