58

I've recently deleted Anaconda and reinstalled python with brew. I've installed everything according to these instructions.

Python works great, and all packages I've tested so far also work. I've got ipython installed, but trying to launch it from the terminal gives:

-bash: ipython: command not found

I've located the installation at:

/usr/local/lib/python2.7/site-packages/ipython

Following older related questions, I've tried adding this path to .bash_profile but got:

-bash: :/usr/local/lib/python2.7/site-packages/ipython: No such file or directory

Whenever terminal starts.

Some more info: Anaconda installed an removed, El-Capitan 10.11.2, python 2.7.

Any help would be much appreciated!

EDIT: added some more info to @cel request:

echo $PATH gives:

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin:/Library/TeX/texbin:/Applications/Sublime Text.app/Contents/SharedSupport/bin

which -a python gives: /usr/local/bin/python and /usr/bin/python.

EDIT: added the output of python -m pip install ipython to cel's request:

Requirement already satisfied (use --upgrade to upgrade): ipython in /usr/local/lib/python2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): traitlets in /usr/local/lib/python2.7/site-packages (from ipython)
Requirement already satisfied (use --upgrade to upgrade): pickleshare in /usr/local/lib/python2.7/site-packages (from ipython)
Requirement already satisfied (use --upgrade to upgrade): simplegeneric>0.8 in /usr/local/lib/python2.7/site-packages (from ipython)
Requirement already satisfied (use --upgrade to upgrade): decorator in /usr/local/lib/python2.7/site-packages (from ipython)
Requirement already satisfied (use --upgrade to upgrade): gnureadline in /usr/local/lib/python2.7/site-packages (from ipython)
Requirement already satisfied (use --upgrade to upgrade): appnope in /usr/local/lib/python2.7/site-packages (from ipython)
Requirement already satisfied (use --upgrade to upgrade): pexpect in /usr/local/lib/python2.7/site-packages (from ipython)
Requirement already satisfied (use --upgrade to upgrade): ipython-genutils in /usr/local/lib/python2.7/site-packages (from traitlets->ipython)
Requirement already satisfied (use --upgrade to upgrade): path.py in /usr/local/lib/python2.7/site-packages (from pickleshare->ipython)
Requirement already satisfied (use --upgrade to upgrade): ptyprocess>=0.5 in /usr/local/lib/python2.7/site-packages (from pexpect->ipython)
Azat Ibrakov
  • 9,998
  • 9
  • 38
  • 50
Adam Haber
  • 683
  • 1
  • 6
  • 8
  • You may want to remove `/usr/local/lib/python2.7/site-packages/ipython` from your path again. This is not how the `PATH` variable works. After that, please restart your terminal, and add the output of `echo $PATH` and `which -a python` to your question. – cel Dec 23 '15 at 20:43
  • Thanks for your reply. I removed it from .bash_profile (I assume this is what you meant), restarted terminal and ipython still doesn't work. `echo $PATH` gives: `/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin:/Library/TeX/texbin:/Applications/Sublime Text.app/Contents/SharedSupport/bin` and `which -a python` gives: `/usr/local/bin/python` and `/usr/bin/python`. – Adam Haber Dec 24 '15 at 08:51
  • You can install ipython via `python -m pip install ipython`, after that you should be able to start ipython from command line. – cel Dec 24 '15 at 09:17
  • I just tried - got a bunch of `Requirement already satisfied` (I can attach if you think it might help), after which I got the same `-bash: ipython: command not found` from before... – Adam Haber Dec 24 '15 at 10:35
  • Yes, the output would be helpful. – cel Dec 24 '15 at 10:57
  • added the output of `python -m pip install ipython` to the original question. – Adam Haber Dec 24 '15 at 18:18
  • For those who are trying to add ipython to PATH on Windows, the executable may be under the path "C:\Users\\AppData\Local\Programs\Python\Python\Scripts". Adding this folder to PATH (using `setx path "%PATH%;C:\Users\\AppData\Local\Programs\Python\Python\Scripts"`) allowed me to launch ipython from the terminal by running `ipython`. – Lfppfs Mar 22 '22 at 21:03

10 Answers10

95

Searching the web for "bash: ipython: command not found" turns up several hits (including this SO question), but they're not particularly helpful. From the sound of it, you have IPython, the Python package installed, but ipython—the entry point (i.e., wrapper/launcher script) for it—is missing for whatever reason. To check whether this is the case, try running:

% python -m IPython
Python 2.7.9 (default, Feb 10 2015, 03:28:08) 
Type "copyright", "credits" or "license" for more information.

IPython 4.0.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]:

If that brings up IPython, then you might try making a shell alias as the SO answer linked above suggests, i.e., put something like this in your shell's startup script: alias ipython='python -m IPython'. Or, create the launcher script yourself. For me, it lives in /usr/local/bin/ipython and contains the following:

#!/usr/local/opt/python/bin/python2.7

# -*- coding: utf-8 -*-
import re
import sys

from IPython import start_ipython

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(start_ipython())

If this helps, please consider up-voting the other SO question as well...

UPDATE: Here are some more possibly-relevant links:

starball
  • 20,030
  • 7
  • 43
  • 238
evadeflow
  • 4,704
  • 38
  • 51
  • 9
    Thanks! It was indeed a wrapper/launcher issue, and was resolved by adding `alias ipython='python -m IPython'` to `.bash_profile`. Upvoted the question you referred to as well. – Adam Haber Dec 24 '15 at 20:32
  • @GoingMyWay probably because python sees `IPython` as a module somehow – n00shie Jan 03 '19 at 00:10
  • 1
    If this doesn't work for you, try adding `alias ipython='python3 -m IPython'` to `.bash_profile`. – Jacob Stern Oct 30 '20 at 20:37
  • as @parth92 writes in his answer, your solution only works for a little amount of packages. For both solutions, alias and launcher script, you have to address each package. I need a global, more dynamic solution. – Timo Mar 03 '21 at 16:38
  • `alias ipython='python -m IPython'` in self-created `.bashrc` - file using `MINGW64` - git-bash on `Windows 10` did it for me. – Andreas L. Jun 11 '21 at 12:45
  • I use `windows` 10, `Python app` from the store and `wsl2`. I get no output with `python3.exe` and `which python3` throws `/mnt/c/Users/User/AppData/Local/Microsoft/WindowsApps/python3.exe`. In `path` I have `../mnt/c/Users/User/AppData/Local/Microsoft/WindowsApps`. Is it a new question or can you help? – Timo Jul 17 '21 at 17:33
19

The answer given by @evadeflow does the job, but there are several other packages installed with pip and it will be very uncomfortable to keep adding alias for each of them. A rather elegant way would be to add the path where these packages are installed to the $PATH variable. In my case adding the following line in ~/.bashrc did the job:

export PATH=$PATH:/home/my_user_name/.local/bin

Addl refs: https://askubuntu.com/q/551990/632996; https://askubuntu.com/q/556090

Parth92
  • 369
  • 3
  • 4
  • 1
    Your intensions are good yet your provide a solution to a problem that does not exist. The OP reported that "Python works great, and all packages [...] tested so far also work". – MaxPowers Sep 22 '18 at 05:58
  • Didn't get you.. We are talking about ipython, right? Python was working great in my case as well. – Parth92 Sep 22 '18 at 10:23
  • 2
    This answer *is* useful, because in my case pip installed the ipython launcher into `~/.local/bin` which wasn't in my `PATH`. That is the root cause of why `ipython` wasn't a valid command. – davidA Jan 22 '19 at 00:39
  • 2
    In my case, this step of adding the installed path to the $PATH variable was done automatically by the python3.7 OSX installer I downloaded from python.org -- there was a file `~/.bash_profile` created which did this. When I read this answer I checked to see what my `~/.bashrc` looked like (new computer) and saw that I just had to `source ~/.bash_profile` to get the path to update. – rajan Aug 11 '19 at 15:41
  • 1
    meanwhile `ipython notebook` has been deprecated. if you have made it up to this point, try `jupyter notebook` instead. – Richard Nov 23 '19 at 17:33
11

What worked for me was to unistall using:

~pip3 uninstall ipython

and then:

~sudo pip3 install ipython

I'm running this on (W10)WSL2 with a Debian.

Robert SIlva
  • 139
  • 2
  • 7
  • This worked for me. IPython was installed to `.local/bin` but I'm using a conda env so it should not redirect here. I had t uninstall it from `.local/bin` and reinstall it in my conda env. Thanks! – rayryeng Dec 19 '22 at 19:12
7

for python3

python3 -m IPython

Naitik Shah
  • 301
  • 2
  • 9
4

If working with Python3, just try:

ipython3

It worked for me.

oz19
  • 1,616
  • 1
  • 17
  • 22
3

Sometimes you just need to source your bash_profile after you successfully installed anaconda.

source ~/.bash_profile
hemanta
  • 1,405
  • 2
  • 13
  • 23
0

For anaconda users:

conda install -c conda-forge ipywidgets
Noman Tanveer
  • 175
  • 1
  • 2
  • 9
0

for most people:

pip install ipython 

for those who need mirror (if installation is very slow)

pip install ipython -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com 
dl wu
  • 154
  • 1
  • 2
  • 11
0

If you are using Apple Silicon Macbook, mostly you are using zsh now. So for me the following worked.

source ~/.zshrc

Quit the terminal after this, and open it back and try. Hope it helps someone.

-1

I installed ipython using apt in Ubuntu 18.04 as follows:

sudo apt install python-ipython

Then, the 'ipython' command didn't work and I got the same "Command not found" error mentioned above. The same happened after installed python3-python. However, then I tried sudo apt install ipython and the correct wrappers were installed. I don't know if something similar happens with pip, but that is my experience with apt.

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61