0

I've installed ipython inside virtualenv on my macOS. My PATH environment variable also shows virtualenv path to be at the beginning. which command also shows that ipython at the correct location.

The problem is, when I run ipython, the shell is finding the previous installation in an odd place. Here's some examples:

(csv_import) $ ipython
-bash: /usr/local/bin/ipython: /usr/local/opt/python3/bin/python3.6: bad interpreter: No such file or directory
(csv_import) $ 
(csv_import) $ which ipython
/Users/zeinep/.virtualenvs/csv_import/bin/ipython
(csv_import) $ 
(csv_import) $ echo $PATH
/Users/zeinep/.virtualenvs/csv_import/bin:/Users/zeinep/.avn/bin:/Users/zeinep/.nvm/versions/node/v10.14.1/bin:/usr/local/lib/python3.6/bin:/Users/zeinep/Library/Python/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
(csv_import) $ 
(csv_import) $ 
(csv_import) $ /Users/zeinep/.virtualenvs/csv_import/bin/ipython
Python 3.6.5 (default, Jun 17 2018, 12:13:06) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.3.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]:         

As can be seen, if I use a full path, it works. Otherwise, old installation at /usr/local/bin/ipython is run even though the shell should be finding the one in in virtualenv as far as I can see.

terdon
  • 242,166
tayfun
  • 103
  • What operating system are you using? Is that macOS? – terdon Feb 28 '19 at 14:54
  • @terdon yes, this is macOS – tayfun Feb 28 '19 at 15:00
  • OK. If you've installed in in a virtualenv, why are you trying to run it outside the virtualenv? Does it work of you do . /Users/zeinep/.virtualenvs/csv_import/bin/activate (or whatever the right command is to activate the virtualenv) and then run ipython? – terdon Feb 28 '19 at 15:02
  • 1
    @JeffSchaller it seems like that solved it! Thanks! – tayfun Feb 28 '19 at 15:02
  • @terdon it's inside virtualenv. That (csv_import) at the beginning is telling me I'm inside the virtual env. – tayfun Feb 28 '19 at 15:03

1 Answers1

3

You apparently added /Users/zeinep/.virtualenvs/csv_import/bin to your $PATH after bash had saved (hashed) the /usr/local/bin version. The fix is as simple as hash -d ipython.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255