How to permenantly set PYTHONPATH for 2.6 and 3.0?

Thread Solved

Join Date: Sep 2009
Posts: 9
Reputation: i are smart is an unknown quantity at this point 
Solved Threads: 0
i are smart i are smart is offline Offline
Newbie Poster

How to permenantly set PYTHONPATH for 2.6 and 3.0?

 
0
  #1
28 Days Ago
So I did some research and learn that you use the sys module to set the path for 2.5:

import sys
sys.path.append('usr/local/lib/python2.5/site-packages/')

And that would set the path for 2.5 permanently, but if i do the samething for 2.6 or 3.0, it will not work the next time I open the interpreter.

I thought this path was suppose to be set by default. it's not so i'm trying to set it.

help please
thanks
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 888
Reputation: Gribouillis has a spectacular aura about Gribouillis has a spectacular aura about Gribouillis has a spectacular aura about 
Solved Threads: 209
Gribouillis's Avatar
Gribouillis Gribouillis is offline Offline
Practically a Posting Shark
 
0
  #2
28 Days Ago
You can get the path to the site-packages directory like this
  1. >>> import os
  2. >>> os.path.join(os.path.split(os.__file__)[0], "site-packages")
  3. '/usr/lib64/python2.6/site-packages'
With python 3:
  1. >>> import os
  2. >>> os.path.join(os.path.split(os.__file__)[0], "site-packages")
  3. '/usr/local/lib/python3.1/site-packages'
(on the same machine).

However, you shouldn't normally need to put the site-packages in sys.path yourself. I'd like to see the value of your sys.path just after you start python.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 9
Reputation: i are smart is an unknown quantity at this point 
Solved Threads: 0
i are smart i are smart is offline Offline
Newbie Poster
 
0
  #3
28 Days Ago
Originally Posted by Gribouillis View Post
You can get the path to the site-packages directory like this
  1. >>> import os
  2. >>> os.path.join(os.path.split(os.__file__)[0], "site-packages")
  3. '/usr/lib64/python2.6/site-packages'
With python 3:
  1. >>> import os
  2. >>> os.path.join(os.path.split(os.__file__)[0], "site-packages")
  3. '/usr/local/lib/python3.1/site-packages'
(on the same machine).

However, you shouldn't normally need to put the site-packages in sys.path yourself. I'd like to see the value of your sys.path just after you start python.
Doesn't even work temporarily.

"No module name file.py" after i did what you wrote and attempted to image a module
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 888
Reputation: Gribouillis has a spectacular aura about Gribouillis has a spectacular aura about Gribouillis has a spectacular aura about 
Solved Threads: 209
Gribouillis's Avatar
Gribouillis Gribouillis is offline Offline
Practically a Posting Shark
 
0
  #4
28 Days Ago
What I wrote doesn't do anything, it only computes the path to site-packages.
What you should do is paste your sys.path here (before you do anything with it).
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 9
Reputation: i are smart is an unknown quantity at this point 
Solved Threads: 0
i are smart i are smart is offline Offline
Newbie Poster
 
0
  #5
27 Days Ago
Originally Posted by Gribouillis View Post
What you should do is paste your sys.path here (before you do anything with it).
What do you mean by that? where is here?
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,954
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 917
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite
 
0
  #6
27 Days Ago
What Gribouillis means is run this code and post the output here on DaniWeb ...
  1. # show the system path for Python ( PYTHONPATH )
  2.  
  3. import sys
  4. print( sys.path )
You need to run this with the version of Python you are interested in.

Also you cannot permanently set PYTHONPATH as it includes information about the current file you are working with.
Last edited by vegaseat; 27 Days Ago at 4:02 pm. Reason: this
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 999
Reputation: woooee is a jewel in the rough woooee is a jewel in the rough woooee is a jewel in the rough 
Solved Threads: 283
woooee woooee is offline Offline
Posting Shark
 
0
  #7
27 Days Ago
I thought this path was suppose to be set by default. it's not so i'm trying to set it.
You can modify it on startup by adding PYTHONPATH to your ~/.bash.rc file, or create one if you don't have it.
export PYTHONPATH=$PYTHONPATH:/path/to/add:/second/path
Linux counter #99383
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 9
Reputation: i are smart is an unknown quantity at this point 
Solved Threads: 0
i are smart i are smart is offline Offline
Newbie Poster
 
0
  #8
27 Days Ago
>>> import sys
>>> sys.path
['/home/junlue', '/usr/bin', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages/PIL', '/usr/lib/python2.6/dist-packages/gst-0.10', '/var/lib/python-support/python2.6', '/usr/lib/python2.6/dist-packages/gtk-2.0', '/var/lib/python-support/python2.6/gtk-2.0', '/usr/local/lib/python2.6/dist-packages']


This is what i got. no site-pakcages though
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 888
Reputation: Gribouillis has a spectacular aura about Gribouillis has a spectacular aura about Gribouillis has a spectacular aura about 
Solved Threads: 209
Gribouillis's Avatar
Gribouillis Gribouillis is offline Offline
Practically a Posting Shark
 
0
  #9
27 Days Ago
I suggest that you write a module
  1. # mystartup.py
  2. import os, sys
  3. site_packages = os.path.join(os.path.split(os.__file__)[0], "site-packages")
  4. sys.path.append(site_packages)
and put this module somewhere on your python path. Then when you write a python program, you simply put
  1. # at the top of your main program
  2. import mystartup
This should work even if you have different versions of python.
Last edited by Gribouillis; 27 Days Ago at 7:44 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 1
Reputation: prouty is an unknown quantity at this point 
Solved Threads: 1
prouty prouty is offline Offline
Newbie Poster

Get site-packages path

 
1
  #10
17 Days Ago
It's quicker to get the path to site-packages right from the command line:
  1. python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"
Last edited by prouty; 17 Days Ago at 1:28 pm. Reason: needed [code]
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC