conda not working correctly with fish shell

2019-08-17 15:41发布

问题:

When using conda environments inside the fish shell on macOS, python still points to system python (/usr/local/bin/python) instead of pointing to the version of python installed by the conda environment (<PATH TO MINICONDA>/envs/<ENV NAME>/bin/python). Everything else (e.g. ipython, jupyter) points to the correct path, just python isn't behaving as expected. How do I fix this?

Details:

Performed the following steps in the following order on macOS Mojave 10.14.3:

  • Installed miniconda (a while back) via the bash install script
  • Installed fish using homebrew
  • Updated config.fish as per: Cannot run source activate with conda in Fish-shell

At this point I can activate and deactivate conda environments successfully inside fish, but as noted at the top of this question python doesn't point to where it should. Everything else (e.g. ipython) works correctly.

conf info returns (same inside bash and fish):

     active environment : base
    active env location : /Users/salamon/dev/miniconda3
            shell level : 1
       user config file : /Users/salamon/.condarc
 populated config files : 
          conda version : 4.6.11
    conda-build version : not installed
         python version : 3.7.1.final.0
       base environment : /Users/salamon/dev/miniconda3  (writable)
           channel URLs : https://repo.anaconda.com/pkgs/main/osx-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/free/osx-64
                          https://repo.anaconda.com/pkgs/free/noarch
                          https://repo.anaconda.com/pkgs/r/osx-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /Users/salamon/dev/miniconda3/pkgs
                          /Users/salamon/.conda/pkgs
       envs directories : /Users/salamon/dev/miniconda3/envs
                          /Users/salamon/.conda/envs
               platform : osx-64
             user-agent : conda/4.6.11 requests/2.21.0 CPython/3.7.1 Darwin/18.2.0 OSX/10.14.3
                UID:GID : 501:20
             netrc file : None
           offline mode : False

Calling which python in bash:

/Users/salamon/dev/miniconda3/bin/python

And in fish:

/usr/local/bin/python

Any help would be most appreciated, thanks.

回答1:

python doesn't point to where it should

Quite simply, that means that there is a path component that includes a python before the one you want. In this case /usr/local/bin is before /envs//bin/ in $PATH (if it's in there at all).

See command -sa python, which should print all pythons it can, and adjust your $PATH accordingly, possibly by putting the one you want into $fish_user_paths, which is prepended to $PATH.