osx - Can't run the Python interpreter in Mac's Terminal

07
2014-07
  • g_rmz

    At the moment i'm on Mavericks, and i just uninstalled homebrew. With homebrew i had installed python, but after uninstalling it my terminal can't start the python interpreter. I receive this message:

    -bash: /usr/local/bin/python: No such file or directory

    There is some kind of configuration that i have to restore for execute the native version of python?

  • Answers
  • mipadi

    Restarting Terminal will probably do the trick.

  • BenjiWiebe

    Simple answer: You could run hash -r, which would cause bash (your shell) to forget the locations of the executables, and "re-search" for them in $PATH.

    More in-depth answer: By default, bash stores commands and their locations in a table (hash). It then only needs to search $PATH once per command, and search the table for each time you run the command again.
    Restarting bash will clear the hash table, but if you don't want to restart it, hash -r (to clear the table) or hash -p commandname (to clear just one entry) will work.


  • Related Question

    Help getting iPython to run from the OSX terminal
  • PizzAzzra

    Got a heads up from stackoverflow.com to ask the question here.

    I'm going through the matplotlib documentation and prepared to use the iPython interactive Python shell with ipython -pylab. However I get this:

    MBP:~ Me$ ipython -pylab
    -bash: ipython: command not found
    

    Did I fail to install iPython? I used easy_install as advised.

    Any ideas?

    Update

    Thought I'd just say that I found the iPython "executable" in /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin after doing a Spotlight search.

    Still a little confused as to what to do.


  • Related Answers
  • fideli

    Looks like your Python 2.6 installation is through MacPorts, based on the /opt/local prefix. If you didn't install it with MacPorts and have your own reason for using /opt/local, ignore this answer. If you did, you can install ipython with port.

    port install py26-ipython
    

    Make sure that your $PATH environment variable is set to include /opt/local/bin. This should have been done by the MacPorts installer. My ~/.profile looks like:

    # MacPorts Installer addition on 2009-03-05_at_21:11:52: adding an appropriate PATH variable for use with MacPorts.
    export PATH=/opt/local/bin:/opt/local/sbin:$PATH
    # Finished adapting your PATH environment variable for use with MacPorts.
    
    
    # MacPorts Installer addition on 2009-03-05_at_21:11:52: adding an appropriate MANPATH variable for use with MacPorts.
    export MANPATH=/opt/local/share/man:$MANPATH
    # Finished adapting your MANPATH environment variable for use with MacPorts.
    

    I would be careful using easy_install in conjunction with MacPorts python, especially for modules that MacPorts already provides. For example, MacPorts ipython puts the executable at /opt/local/bin/ipython2.6 along with /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/ipython

    EDIT
    To uninstall the easy_installed version of ipython, from what I know you'll need to manually delete the associated files. I'm taking a leap here based on my installation of ipython. First delete the executables:

    /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/ipcluster
    /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/ipcontroller
    /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/ipengine
    /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/iptest
    /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/ipython
    /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/ipython-wx
    /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/ipythonx
    /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/irunner
    /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/pycolor
    

    Then, delete the folder and egg-info in site-packages:

    /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/IPython/
    /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/ipython-0.10-py2.6.egg-info
    

    Then, delete the doc folder:

    /opt/local/Library/Frameworks/Python.framework/Versions/2.6/share/doc/ipython/
    

    Then, delete the man files:

    /opt/local/Library/Frameworks/Python.framework/Versions/2.6/share/man/man1/ipcluster.1.gz
    /opt/local/Library/Frameworks/Python.framework/Versions/2.6/share/man/man1/ipcontroller.1.gz
    /opt/local/Library/Frameworks/Python.framework/Versions/2.6/share/man/man1/ipengine.1.gz
    /opt/local/Library/Frameworks/Python.framework/Versions/2.6/share/man/man1/ipython-wx.1.gz
    /opt/local/Library/Frameworks/Python.framework/Versions/2.6/share/man/man1/ipython.1.gz
    /opt/local/Library/Frameworks/Python.framework/Versions/2.6/share/man/man1/ipythonx.1.gz
    /opt/local/Library/Frameworks/Python.framework/Versions/2.6/share/man/man1/irunner.1.gz
    /opt/local/Library/Frameworks/Python.framework/Versions/2.6/share/man/man1/pycolor.1.gz
    

    Finally, open the file /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/easy-install.pth and see if there is a line referring to the ipython egg. Delete that.

  • Darren Newton

    This sounds like a problem with your PATH. Check your ~/.profile or ~/.bashrc in Terminal and make sure that /usr/local/bin is in your $PATH before the Apple defaults.

    PATH="/usr/local/bin:/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}"
    

    More information here: http://ipython.scipy.org/moin/Py4Science/InstallationOSX