#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

    Prepend to sys.path


    Hi,

    I am trying to prepend to sys.path in linux with a local directory containing modules I have installed. I'm trying to prepend to sys.path so I load my local installations instead of the global ones. I've tried to set PYTHONPATH, however this adds the directories in after the '/usr/lib/python2.6/site-packages'. Is there anyway to permanently prepend to sys.path without having to use sys.path.insert(1,'/my/path') in every script?

    Thanks!
    Brody
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,854
    Rep Power
    481
    put into ~/.bashrc

    PYTHONPATH=mypath:$PYTHONPATH
    export PYTHONPATH



    Make an alias for python
    Code:
    alias PYTHON="PYTHONPATH=mypath:$PYTHONPATH python"

    Use the PYTHONSTARTUP environment variable.
    Investigate the python command line
    http://docs.python.org/3/using/cmdline.html?highlight=pythonstartup#PYTHONSTARTUP
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo