1

I am on a Mac running macOS Mojave. I run Iterm2 for terminal and fish version 3.0.0. I also use pipenv to manage my local development.

I have this problem where when I activate a python virtual env, via >pipenv shell, the virtual env path is slotted into the middle of the PATH list after the /usr/local/bin which on a Mac is where Homebrew installs binaries. Therefore also the virtual env is activated when I type >which python, I get the python from the system and not the virtual env as I would expect.

Example

Path before virtual env activation with pipenv shell command

PATH=/Users/napo/bin:/Users/napo/.local/bin:/Users/napo/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/share/dotnet:~/.dotnet/tools:/usr/local/sbin:/usr/local/opt/python@2/bin

Path after virtual env activation with pipenv shell command

PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/share/dotnet:~/.dotnet/tools:/Users/napo/.local/share/virtualenvs/learn-gXU4lJPg/bin:/usr/local/Cellar/pipenv/2018.11.26/libexec/tools:/Users/napo/bin:/Users/napo/.local/bin:/Users/napo/.cargo/bin:/usr/local/sbin:/usr/local/opt/python@2/bin

Apart from the problem with duplicates of paths entries, one can see that /Users/napo/.local/share/virtualenvs/learn-gXU4lJPg/bin has been slotted somewhere in the middle of that list.

I'll be most grateful for a fix. Below is my current full config.fish

if status --is-login
    # Homebrew
    set -x HOMEBREW_INSTALL_CLEANUP 1

    # Golang
    set -gx GOPATH ~/go/

    # Don't write bytecode, Python!
    set -x PYTHONDONTWRITEBYTECODE 1
    set -x PIPENV_SHELL_FANCY 1
    set -x PIPENV_MAX_SUBPROCESS 64
    set -x EDITOR nvim

    set -gx OSTYPE macOS
    set -gx WORKON_HOME /Users/napo/.local/share/virtualenvs

    # android sdk
    set -gx ANDROID_NDK_HOME /usr/local/share/android-ndk
    set -gx ANDROID_SDK_ROOT /usr/local/share/android-sdk

    # Make fzf respect .gitignore using fd command

    set -gx FZF_DEFAULT_COMMAND 'rg --files'

    # Now fzf (w/o pipe) will use fd instead of find
    # To apply the command to CTRL-T as well
    set -gx FZF_CTRL_T_COMMAND $FZF_DEFAULT_COMMAND

    set -gx VIMCONFIG ~/.config/nvim
    set -gx VIMDATA ~/.local/share/nvim
    set -gx VISUAL nvim

    # PATHS
    set -gx PATH /Users/napo/bin /Users/napo/.local/bin /Users/napo/.cargo/bin $PATH
    set -gx PATH $PATH /usr/local/sbin /usr/local/opt/python@2/bin

    neofetch
end

# Use personal aliases
if test -e "$HOME/.config/fish/path.fish"
    source ~/.config/fish/path.fish
end

if test -e "$HOME/.config/fish/aliases.fish"
    source ~/.config/fish/aliases.fish
end

if test -e "$HOME/.config/fish/chpwd.fish"
    source ~/.config/fish/chpwd.fish
end

if test -e "$HOME/.config/fish/functions.fish"
    source ~/.config/fish/functions.fish
end

# for things not checked into git.
if test -e "$HOME/.extra.fish"
    source ~/.extra.fish
end

# Prefer GB English and use UTF-8
set -x LC_ALL en_GB.UTF-8
set -x LANG en_GB

set -g theme_nerd_fonts yes
set -g theme_show_exit_status yes

# Allow 256 colors in iTerm2 for pretty vim colors
#set -gx TERM xterm-256color
set -gx CLICOLOR 1

# better ls colors
eval (gdircolors --c-shell $HOME/dircolors)

# Remove fish greeting
set fish_greeting

# highlighting inside manpages and elsewhere
set -gx LESS_TERMCAP_mb \e'[01;31m' # begin blinking
set -gx LESS_TERMCAP_md \e'[01;38;5;74m' # begin bold
set -gx LESS_TERMCAP_me \e'[0m' # end mode
set -gx LESS_TERMCAP_se \e'[0m' # end standout-mode
set -gx LESS_TERMCAP_so \e'[38;5;246m' # begin standout-mode - info box
set -gx LESS_TERMCAP_ue \e'[0m' # end underline
set -gx LESS_TERMCAP_us \e'[04;38;5;146m' # begin underline

# jump config
status --is-interactive
and source (jump shell |psub)

# direnv config
eval (direnv hook fish)

Thanks

0

This is a problem with fish 3.0.0 - see https://github.com/fish-shell/fish-shell/issues/5456.

The suggestion there is to add a reordering function to your startup:

function path-reordered -d "Echos the elements of $PATH, reordered such that custom paths precede standard system paths. This can be used to work around a fish 3.0.0 bug in which sub-shells fail to respect path ordering."
  set -l sys_paths

  for p in $PATH
      if string match -q -r '^/usr/|^/s?bin(/|$)' $p
          set -a sys_paths $p
      else
          echo $p
      end
  end

  for p in $sys_paths; echo $p; end
end

Then, in config.fish:

if status --is-login
     set PATH $HOME/.local/bin $PATH
     # etc.
else
     set PATH (path-reordered)
end

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.