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

Reply

Python - Re: PYTHONPATH on Mac 10.5

 
Thread Tools Search this Thread
Old 02-26-2009, 12:48 AM   #1
Default Re: PYTHONPATH on Mac 10.5



On Feb 25, 2009, at 3:20 PM, Vincent Davis wrote:

> I have looked around for a good howto setup PYTHONPATH on Mac os x
> 10.5 Although I get many results I am not sure which is correct. I
> am not
> sure if it is different for 10.5 over previous versions. Does anyone
> know of
> a well documented set of instructions.
>
> Is there a way to specify a module location or working directory?
> Which is
> best? Or should I just add location to PYTHONPATH?



Hi Vincent,
There are different instructions on how to set PYTHONPATH because it
solves a problem (how to organize one's Python modules) that has more
than one solution. It's sort of like asking "How should I organize my
email?" Different strokes for different folks.

Me, I don't use PYTHONPATH at all. Most of the stuff I want to import
is already available in site-packages. If not, I can add a .pth file
to site-packages that tells Python where to find the source. You can
read about .pth files here:
http://docs.python.org/library/site.html


> In my python scripts I specify which python I want to use like this
> #!/Library/Frameworks/Python.framework/Versions/4.1.30101/bin/python


Yikes! Your scripts won't be too portable then, will they? I'm on OS X
10.5 and I don't have a directory like that. A common, more portable
alternative is this:

#!/usr/bin/env python

That relies (obviously) on /usr/bin/env being present which means that
your scripts won't work on Windows machines, for instance. But it's a
whole lot more portable than what you've got now. You don't need a
shebang line at all if you're willing to launch your scripts by typing
`python foo.py` at the command line. That will merely execute
whichever python appears first in your path. I used to always use the /
usr/bin/env shebang line that I described above, but I do so less
often now. It's one less dependency to deal with.

So, in short, PYTHONPATH doesn't need to be set at all, and you can
switch the shebang line to this:

#!/usr/bin/env python

Or do away with it entirely.

This isn't a complete answer but has it been at least somewhat helpful?

Cheers
Philip








Philip Semanchuk
  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




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