Is path broken for anaconda ipython?

2019-06-20 05:35发布

问题:

I wish to use anaconda distribution of ipython, but typing ipython at the terminal produces an error message:

Traceback (most recent call last):
  File "/usr/local/bin/ipython", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2603, in <module>
    working_set.require(__requires__)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 666, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 565, in resolve
    raise DistributionNotFound(req)  # XXX put more info here
pkg_resources.DistributionNotFound: ipython==0.13.1

Adding PATH to .bash_profile as below produces the same error message. Asking which python produces //anaconda/bin/python, and which ipython produces /usr/local/bin/ipython. How can I fix this such that ipython launches anaconda ipython?

# MacPorts Installer addition on 2012-11-03_at_23:50:01: 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.
# Add colors to terminal
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad

# added by Anaconda 1.6.1 installer
export PATH="//anaconda/bin:$PATH"
export PATH=/anaconda//bin/isympy:$PATH

# added to Homebrew: bad command
export PATH=/usr/local/bin:$PATH

Update: I updated anaconda and ipython using conda update as suggested, but still get the same error message.

Update 2: Thanks for all the suggestions. I modified /usr/local/bin/ipython as follows:

#!//anaconda/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'ipython==1.1.0','console_scripts','ipython'
__requires__ = 'ipython==1.1.0'
import sys
from pkg_resources import load_entry_point

sys.exit(
   load_entry_point('ipython==1.1.0', 'console_scripts', 'ipython')()
)

Now which ipython produces //anaconda/bin/ipython, and ipython launches.

回答1:

One possible reason is that there are multiple ipython versions installed e.g., brew might install to /usr/local/bin, conda might install to /anaconda/bin (it is just a guess). The advice from similar issue is to remove all ipython installation completely and install the one that you will use.



回答2:

Your problem is in your $PATH. If you look at your traceback, it's running /usr/local/bin/ipython - this is the one that is installed by Homebrew, and not by Anaconda. (Anaconda installs everything into /anaconda/bin.)

The reason this is getting picked up is because the very last line of your .bash_profile sticks /usr/local/bin at the front of your path. This means that the ipython that you installed via Homebrew is masking the one that's installed by Anaconda.

You have two options:

  1. Uninstall the ipython that Homebrew installed, and just use Anaconda for your Python packages.

  2. In your .bash_profile, move the Homebrew PATH modification line above the Anaconda one. This way, Anaconda's ipython, python, and various other Python commands will take precedence.

Remember, if you change your .bash_profile, you need to close your Terminal and start a new one for the changes to take effect.



回答3:

It looks like your path is completely ok. Notice that the error comes from "/usr/local/bin/ipython". It is not a bash error, it is more likely an error involving setup_tools, or pip, that is Python packaging tools. Bash finds ipython and executes ipython startup file but encounters an error there.

The error appears to be saying that your version of ipython is incompatible. Have you tried doing something like this?

 conda update conda
 conda update ipython

Updaing conda and ipython is recommended in iPython documentation. Perhaps this will fix the problem. If not, then add an information saying that you updated conda and ipython to your question.



回答4:

Ensure you check the path to the Python executable specified at the start of the script. When I installed iPython it was defined as:

#!/usr/bin/python

Instead of:

#!/usr/local/bin/python

Hence the default OS X install of Python was being used instead of my brew installed version.



回答5:

For me was slightly different because even with Anaconda installed wasn't able to find the command or to run ipython and wasn't able to find the PATH. My solution was to run these commands:

nano ~/.bash_profile
export PATH="/anaconda3/bin:$PATH"
source ~/.bash_profile

and then to check conda version:

conda

and I update conda and ipython running:

conda update conda
conda update ipython

Hope this could help someone. This helped me: https://stackoverflow.com/a/49925193/3351569