LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices



Reply
 
Search this Thread
Old 12-25-2012, 08:48 AM   #1
lolnameless
LQ Newbie
 
Registered: Jan 2012
Location: Hong Kong
Distribution: Slackware
Posts: 18

Rep: Reputation: Disabled
Is there a good workaround to add search path in python?


Hi Slackers,

I have non-official software package in prefix=/usr/local instead of /usr.

In Slackware64-current(or maybe all recent Slackware),the official python package has prefix=/usr,which has sys.path like this.
Code:
$ python
Python 2.7.3 (default, Jul  3 2012, 19:58:39)
[GCC 4.7.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print sys.path
['', '/usr/lib64/python27.zip', '/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr
/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7/site-packages', '/usr/lib64/python2.7/site-
packages/PIL', '/usr/lib64/python2.7/site-packages/gtk-2.0']
You see,python libraries installed under /usr/local(or anything else) cant be searched by the /usr/bin/python interpreter. That is the problem.

Another problem is that there is sooo many way to do this,
like,changing PYTHONPATH,install yet another python in /usr/local,
or there are python specific ways like pip and virtualenv.
However,I don't use python(at the moment),i just want to change the search path such that the settings is persistent across update/upgrade/adding new software...etc.I would like to see how you guys do it.

Thanks

Last edited by lolnameless; 12-25-2012 at 08:50 AM.
 
Old 12-25-2012, 11:11 AM   #2
audriusk
Member
 
Registered: Mar 2011
Location: Klaipėda, Lithuania
Distribution: Slackware
Posts: 248

Rep: Reputation: 107Reputation: 107
Open /usr/lib64/python2.7/site.py and find the following lines:
Code:
# Prefixes for site-packages; add additional prefixes like /usr/local here
PREFIXES = [sys.prefix, sys.exec_prefix]
Change the second line to:
Code:
PREFIXES = [sys.prefix, sys.exec_prefix, '/usr/local']
Or create a file /usr/lib64/python2.7/site-packages/sitecustomize.py and put this into it:
Code:
import site
site.addsitedir('/usr/local/lib64/python2.7/site-packages')
Similarly add more paths if there's a need.
 
1 members found this post helpful.
Old 12-25-2012, 12:26 PM   #3
lolnameless
LQ Newbie
 
Registered: Jan 2012
Location: Hong Kong
Distribution: Slackware
Posts: 18

Original Poster
Rep: Reputation: Disabled
Thank you Audriusk.
Yes,this is the way to do it.
Mark it as solved~
 
  


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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I add python to the PATH... trist007 Linux - Newbie 2 03-21-2009 10:11 AM
How to (temporarily) add a library search path? G00fy Programming 4 07-03-2007 09:06 AM
I need to add a directory to the search path johnjafa Linux - Software 1 01-06-2005 02:43 PM
How to Chnage Python's module search path (sys.path)? lramos85 Linux - Software 1 05-02-2004 07:10 PM
How do I change python search path Giallo998 Linux - Software 1 10-22-2003 08:27 PM


All times are GMT -5. The time now is 05:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration