Correct PATH location in .profile

1.3k views Asked by At

I am running into some issues with installing python modules while using python versus ipython and I think it has to do with my .profile and .bash_profile.

My desired setup is to be able to leverage homebrew, pip and easy_install to install programs and modules, and have them install into the correct location so python and ipython point to the same source. Here is the output of which for various programs:

mike$ which brew
/usr/local/bin/brew

mike$ which ruby
/usr/bin/ruby

mike$ which python
/usr/local/bin/python

mike$ which ipython
/usr/local/share/python/ipython

.profile output:

PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"

.bash_profile output:

if [ -f ~/.bashrc ]; then source ~/.bashrc ; fi

export PATH=/usr/local/share/python:$PATH

What changes should I make so that when I install modules or programs, they automatically go into the correct location?

1

There are 1 answers

1
cronburg On

Your PATH tells bash which executables to run when you type a certain command, not which modules to load in python. You can check where modules are installed by doing:

import module_name
print module_name.__file__

You're problem is likely due to either running different versions of python or having ipython use a different PYTHONPATH. Try doing:

import os
print os.environ["PYTHONPATH"]

in the two different interpreters. If it raises a KeyError, then try setting PYTHONPATH in your .bash_profile to the libraries you want, e.g.:

export PYTHONPATH=.:/usr/local/lib/python

If it's a version issue, then use the appropriate pip command (e.g. pip-2.7 - see pip: dealing with multiple Python versions?). The same applies for easy_install.

For ruby I recommend using rvm and gem install (steps 6-8 of http://www.moncefbelyamani.com/how-to-install-xcode-homebrew-git-rvm-ruby-on-mac/). These tools are similar to python's pip and easy_install, allowing for seamless installation of ruby gems.