How to import multiple locations to PYTHONPATH (bash)

Anake picture Anake · Apr 24, 2011 · Viewed 31.5k times · Source

I know you can add multiple locations to python path by separating them by colons ie:

export PYTHONPATH=~/one/location:~/second/location

etc.

I have several locations to add and it looks messy using the above method. Is there a way of adding them in multiple lines? This is what I tried and the last line erases the first.

export PYTHONPATH=~/one/location
export PYTHONPATH=~/second/location

Thanks

Answer

John Zwinck picture John Zwinck · Apr 24, 2011
PYTHONPATH=~/one/location:$PYTHONPATH
PYTHONPATH=~/second/location:$PYTHONPATH
export PYTHONPATH

Note the order here: I've made them so that each has higher precedence than the one before; you could switch what goes on each side of the colon if you want later entries to have lower precedence.