Clean Up The Python Installation

- 1 answer

It seems that python can be found in three different places in my Mac OS. See below. Is there anything wrong? Should I and how can I clean up my python installation without reinstalling the OS? In fact, I recently experience some strange behavior when using Python.





What you need to do is update the paths in your .bashrc (or more likely .profile as you are on mac). This should be accessible from your home directory. ~/.profile and can be edited using nano.

You can then tell your terminal which set of libraries and version of python to use by adding the following. Note more than one may be added this way, so only have one bin directory with an executable python program!

  export PATH=$PATH:/usr/local/lib/python2.7/site-packages

If you want to add other libraries / execute your own programs as if they were in the library or save yourself reinstalling everything, you can use the following:

  export PYTHONPATH=/Library/Python/2.7/site-packages'

Finally if you wanted to run a script/preload libraries every time you open python, you can make a .pythonstartup file in your home directory as well.

  export PYTHONSTARTUP=$HOME/.pythonstartup

As for cleaning up, most distributions tend to update you paths when they are installed, which is most likely what is causing your problems. So all you probably have to do is look at your .profile file and remove two of the three paths above.

Hope that helps!