Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want my system to use /usr/bin/python, but it's currently using /opt/local/bin/python, which points to /usr/bin/python2.6. I tried modifying the PATH variable in my .bashrc as

PATH=~/bin:$PATH

...and then set a symbolic link in ~/bin to point to /usr/bin/python. i.e. ~/bin/python --> /usr/bin/python

I figured this might prioritize this symlink over the /opt/local version if it came before the other one in the PATH variable, but when I opened a new shell I still found python pointing to /opt/local/bin. Any advice on a good way to get the system to use /usr/bin/python?

Also, I usually use ipython as opposed to python directly. I'm assuming that if the system starts to use the correct version of python then ipython would also use that version? If not, how could I also get ipython to use the correct version?

Thanks!

share|improve this question
    
Just to test, I removed /opt/local/bin/python and replaced that link with a link to /usr/bin/python (I guess this may be okay, but I was hoping to not have to touch this and only change the priorities somehow, which would be a preferred solution). This did make it call the correct version of python, but ipython is still using some other version, so doesn't really solve my problem the way I want... –  mindthief Jan 9 '11 at 2:15
    
What you did should make sense. If I may, my guess is that you installed Python using MacPorts. If so, install the python_select port and use it to choose python26-apple. That way, /opt/local/bin/python will point to /usr/bin/python. Ignore this if you are not using MacPorts. –  fideli Jan 9 '11 at 2:15
    
Yes, don't think I used MacPorts, but thanks for the comment. –  mindthief Jan 9 '11 at 2:18
    
You'll need to build iPython against the system Python in order for it to use it. –  fideli Jan 9 '11 at 2:18
    
iPython might also be specifying a Python version in its scripts, check the shebang (first line starting with #!). –  TryPyPy Jan 9 '11 at 9:17

1 Answer 1

I can't tell exactly what's going on with ~/.bashrc, but here's my stab in the dark. If you're using Terminal.app and you haven't changed your preferences, Terminal will by default invoke Bash as an interactive login shell, which doesn't execute commands from ~/.bashrc. As noted, adding

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

to the end of ~/.bash_profile will explicitly tell Bash to execute commands found in ~/.bashrc, if it exists.


Once your system is using the right version of Python, then use that version to install IPython again (using the same options as the original install, I think). Then IPython should be available in the Python version you wanted to use.

IPython's FAQ also covers how to use IPython with two versions of Python simultaneously, if you're interested.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.