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

Reply

Python - Newbie thwarted by sys.path on Vista

 
Thread Tools Search this Thread
Old 08-01-2009, 10:58 PM   #1
Default Newbie thwarted by sys.path on Vista


I'm running Python 3.1 on Vista and I can't figure out how to add my own
directory to sys.path.

The docs suggest that I can either add it to the PYTHONPATH environment
variable or to the PythonPath key in the registry. However, PYTHONPATH
doesn't exist, and updating the registry key has no effect (and in any case
the contents aren't the same as sys.path).

So where does sys.path get its value from, and how do I change it?

--
Michael



Michael M Mason
  Reply With Quote
Old 08-02-2009, 12:32 AM   #2
Jon Clements
 
Posts: n/a
Default Re: Newbie thwarted by sys.path on Vista
On 1 Aug, 22:58, "Michael M Mason" <mich...@altra-optics.co.uk> wrote:
> I'm running Python 3.1 on Vista and I can't figure out how to add my own
> directory to *sys.path.
>
> The docs suggest that I can either add it to the PYTHONPATH environment
> variable or to the PythonPath key in the registry. *However, PYTHONPATH
> doesn't exist, and updating the registry key has no effect (and in any case
> the contents aren't the same as sys.path).
>
> So where does sys.path get its value from, and how do I change it?
>
> --
> Michael


sys.path is just a list. So in your 'main' module where you do most of
your imports, just append or prepend the path you desire (the search
order is left to right). Although, I believe under Windows creating a
system level or user level PYTHONPATH environment variable will enable
Windows to pick it up. Not 100% sure as I don't have a Windows machine
handy.


Jon Clements
  Reply With Quote
Old 08-02-2009, 12:36 AM   #3
Piet van Oostrum
 
Posts: n/a
Default Re: Newbie thwarted by sys.path on Vista
>>>>> "Michael M Mason" <> (MMM) wrote:

>MMM> I'm running Python 3.1 on Vista and I can't figure out how to add my own
>MMM> directory to sys.path.


>MMM> The docs suggest that I can either add it to the PYTHONPATH environment
>MMM> variable or to the PythonPath key in the registry. However, PYTHONPATH
>MMM> doesn't exist,


Then create it.
--
Piet van Oostrum <>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email:


Piet van Oostrum
  Reply With Quote
Old 08-02-2009, 01:26 AM   #4
David Lyon
 
Posts: n/a
Default Re: Newbie thwarted by sys.path on Vista
On Sat, 1 Aug 2009 22:58:53 +0100, "Michael M Mason"
<> wrote:
> I'm running Python 3.1 on Vista and I can't figure out how to add my own
> directory to sys.path.
>
> The docs suggest that I can either add it to the PYTHONPATH environment
> variable or to the PythonPath key in the registry. However, PYTHONPATH
> doesn't exist, and updating the registry key has no effect
>
> So where does sys.path get its value from, and how do I change it?


The simplest hack (worst - but most direct) is that sys.path is a list
and you can use it like any other list. (add, delete, change items in it)

It gets loaded from site.py (in the standardard library) at startup.

Anything else you'll have to ask somebody else.

David


David Lyon
  Reply With Quote
Old 08-02-2009, 01:29 AM   #5
Dave Angel
 
Posts: n/a
Default Re: Newbie thwarted by sys.path on Vista
Michael M Mason wrote:
> <div class="moz-text-flowed" style="font-family: -moz-fixed">I'm
> running Python 3.1 on Vista and I can't figure out how to add my own
> directory to sys.path.
>
> The docs suggest that I can either add it to the PYTHONPATH
> environment variable or to the PythonPath key in the registry.
> However, PYTHONPATH doesn't exist, and updating the registry key has
> no effect (and in any case the contents aren't the same as sys.path).
>
> So where does sys.path get its value from, and how do I change it?
>

sys.path gets its values from several places. The ones I think I know
of are:

current directory (which uses "" rather than the expected ".")
directories listed in PythonPath environment variable
Windows-system directory
relative to the executable (python.exe or pythonw.exe) that's
actually running
relative to the user directory (docs&settings/username/Application
Data ....

If there's no PythonPath variable, it just uses those other items. I
have no idea what it gets from the registry entries.

Anyway, I'd suggest adding it to PythonPath, and if it's empty, just
create it with the directory you need.

I'm hoping you know you can also add to sys.path directly during script
initialization. It's just a list, and is writeable.



Dave Angel
  Reply With Quote
Old 08-02-2009, 07:34 AM   #6
Michael M Mason
 
Posts: n/a
Default Re: Newbie thwarted by sys.path on Vista

"Dave Angel" <> wrote in message
news:mailman.4120.1249172970.8015.python-...
> Michael M Mason wrote:
>> <div class="moz-text-flowed" style="font-family: -moz-fixed">I'm running
>> Python 3.1 on Vista and I can't figure out how to add my own directory to
>> sys.path.


Thanks to Jon, Piet, David and Dave for the responses.

> sys.path gets its values from several places.


Ah, I'd misunderstood the docs: I thought it came from just one place (which
I couldn't find).

> Anyway, I'd suggest adding it to PythonPath, and if it's empty, just
> create it with the directory you need.


Thanks--that worked!

> I'm hoping you know you can also add to sys.path directly during script
> initialization. It's just a list, and is writeable.


Yes, but I'm mainly playing in IDLE and I was getting a bit fed up of
repeatedly typing
import sys
sys.path.append('C:/Users/Michael/Code/Python')
import mystuff

--
Michael




Michael M Mason
  Reply With Quote
Old 08-02-2009, 09:55 AM   #7
Mark Lawrence
 
Posts: n/a
Default Re: Newbie thwarted by sys.path on Vista
Michael M Mason wrote:
>
> "Dave Angel" <> wrote in message
> news:mailman.4120.1249172970.8015.python-...
>> Michael M Mason wrote:
>>> <div class="moz-text-flowed" style="font-family: -moz-fixed">I'm
>>> running Python 3.1 on Vista and I can't figure out how to add my own
>>> directory to sys.path.

>
> Thanks to Jon, Piet, David and Dave for the responses.
>
>> sys.path gets its values from several places.

>
> Ah, I'd misunderstood the docs: I thought it came from just one place
> (which I couldn't find).
>
>> Anyway, I'd suggest adding it to PythonPath, and if it's empty, just
>> create it with the directory you need.

>
> Thanks--that worked!

Be careful, I'm screwed things up on several occasions by placing a file
on PYTHONPATH that overrides a file in the standard library, test.py
being my favourite!
>
>> I'm hoping you know you can also add to sys.path directly during
>> script initialization. It's just a list, and is writeable.

>
> Yes, but I'm mainly playing in IDLE and I was getting a bit fed up of
> repeatedly typing
> import sys
> sys.path.append('C:/Users/Michael/Code/Python')
> import mystuff
>

--
Kindest regards.

Mark Lawrence.



Mark Lawrence
  Reply With Quote
Old 08-02-2009, 10:15 AM   #8
Michael M Mason
 
Posts: n/a
Default Re: Newbie thwarted by sys.path on Vista
"Mark Lawrence" <> wrote in message
news:mailman.4130.1249203322.8015.python-...
> Be careful, I'm screwed things up on several occasions by placing a file
> on PYTHONPATH that overrides a file in the standard library, test.py being
> my favourite!


Thanks. Sure enough, I've already got my own test.py but I hadn't
discovered it was a problem yet...

--
Michael



Michael M Mason
  Reply With Quote
Old 08-02-2009, 12:04 PM   #9
Mark Lawrence
 
Posts: n/a
Default Re: Newbie thwarted by sys.path on Vista
Michael M Mason wrote:
> "Mark Lawrence" <> wrote in message
> news:mailman.4130.1249203322.8015.python-...
>> Be careful, I'm screwed things up on several occasions by placing a
>> file on PYTHONPATH that overrides a file in the standard library,
>> test.py being my favourite!

>
> Thanks. Sure enough, I've already got my own test.py but I hadn't
> discovered it was a problem yet...
>

Typical, tried to reproduce it and can't! Still at least you've been
warned.

--
Kindest regards.

Mark Lawrence.



Mark Lawrence
  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
Gaming problems with MATROX TripleHead2Go & VISTA Ultimate Edition Lionman Gaming 1 09-09-2009 05:34 PM
Windows Vista Service Pack 1 Review Admin Front Page News 0 03-31-2008 12:50 PM
The Vista Dancing Lesson teak A+ Certification 16 08-11-2007 05:21 PM
MCITP: Enterprise Support Technician MileHighWelch MCITP 1 06-19-2007 10:25 PM
Vista: Native DVD Burn Suport? smackedass A+ Certification 5 03-04-2007 05:21 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