Skip to content

pixi shell has different PATH than pixi run when PATH gets modified in rc files #246

Closed

Description

@pavelzw
❯ pixi run which python3
/tmp/project/.pixi/env/bin/python3
❯ pixi shell
❯ which python3
/opt/homebrew/bin/python3

Activity

  1. ruben-arts commented on Aug 2, 2023

    @ruben-arts
    Contributor

    He @pavelzw,
    That would be bad, i'm not able to reproduce it locally:

    ~/test 
    ➜ which python3
    /usr/bin/python3
    
    ~/test 
    ➜ pixi r which python3
    /home/rarts/test/.pixi/env/bin/python3
    
    ~/test 
    ➜ pixi s
    
    ~/test via 🅒 test 
    ➜ which python3
    ~/test/.pixi/env/bin/python3

    Also my in pixi's environment paths are equal:

    ~/test 
    ➜ echo $PATH
    /home/rarts/.local/bin:/home/rarts/bin:/usr/condabin:/usr/lib64/ccache:/home/rarts/.cargo/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/var/lib/snapd/snap/bin:/home/rarts/.local/share/JetBrains/Toolbox/scripts:/home/rarts/.local/share/JetBrains/Toolbox/scripts:/home/rarts/.pixi/bin
    
    ~/test 
    ➜ pixi r echo \$PATH
    /home/rarts/test/.pixi/env/bin:/home/rarts/.local/bin:/home/rarts/bin:/usr/condabin:/usr/lib64/ccache:/home/rarts/.cargo/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/var/lib/snapd/snap/bin:/home/rarts/.local/share/JetBrains/Toolbox/scripts:/home/rarts/.local/share/JetBrains/Toolbox/scripts:/home/rarts/.pixi/bin
    
    ~/test 
    ➜ pixi s
    
    ~/test via 🅒 test 
    ➜ echo $PATH
    /home/rarts/test/.pixi/env/bin:/home/rarts/.local/bin:/home/rarts/bin:/usr/condabin:/usr/lib64/ccache:/home/rarts/.cargo/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/var/lib/snapd/snap/bin:/home/rarts/.local/share/JetBrains/Toolbox/scripts:/home/rarts/.local/share/JetBrains/Toolbox/scripts:/home/rarts/.pixi/bin
    
  2. pavelzw commented on Aug 2, 2023

    @pavelzw
    CollaboratorAuthor

    When I compare both PATHs, I can see that pixi run has .pixi/env/bin at the top while pixi shell doesn't.

    $ pixi run echo \$PATH
    /private/tmp/aaaa/.pixi/env/bin
    /Users/pavel/.local/share/pnpm
    /Users/pavel/.pixi/bin
    /Users/pavel/.local/bin
    /opt/homebrew/bin
    /opt/homebrew/sbin
    /opt/local/bin
    [...]
    
    $ pixi shell
    $ echo $PATH
    /Users/pavel/.local/share/pnpm
    /Users/pavel/.pixi/bin
    /Users/pavel/.local/bin
    /opt/homebrew/bin
    /opt/homebrew/sbin
    # from here it is the same
    /private/tmp/aaaa/.pixi/env/bin
    /Users/pavel/.local/share/pnpm
    /Users/pavel/.pixi/bin
    /Users/pavel/.local/bin
    /opt/homebrew/bin
    /opt/homebrew/sbin
    /opt/local/bin
    [...]

    We can see that in pixi shell it adds the additional PATH stuff that I explicitly added in my .zshrc while it doesn't do that in pixi run.

    Can you reproduce the issue with this?

    $ docker run --rm -it ubuntu
    $ apt update && apt install -y curl
    # use the x86_64 version when not on ARM
    $ curl -Ls https://github.com/prefix-dev/pixi/releases/download/v0.0.8/pixi-aarch64-unknown-linux-musl -o /usr/local/bin/pixi
    $ chmod +x /usr/local/bin/pixi
    $ mkdir /tmp/test /tmp/bin
    $ echo "echo I am a mock python" > /tmp/bin/python3
    $ chmod +x /tmp/bin/python3
    $ echo 'export PATH=/tmp/bin:$PATH' >> ~/.bashrc
    $ bash
    $ cd /tmp/test
    $ pixi init
    $ pixi add python
    $ which python3
    /tmp/bin/python3
    $ pixi run which python3
    /tmp/test/.pixi/env/bin/python3
    $ pixi shell
    $ which python3
    $ /tmp/bin/python3

    This will probably be a common issue since AFAIK homebrew explicitly wants that eval "$(/opt/homebrew/bin/brew shellenv)" is somewhere in your zshrc (and python and other tools will probably also be installed in there).

    ❯ /opt/homebrew/bin/brew shellenv
    export HOMEBREW_PREFIX="/opt/homebrew";
    export HOMEBREW_CELLAR="/opt/homebrew/Cellar";
    export HOMEBREW_REPOSITORY="/opt/homebrew/Homebrew";
    export PATH="/opt/homebrew/bin:/opt/homebrew/sbin${PATH+:$PATH}";
    export MANPATH="/opt/homebrew/share/man${MANPATH+:$MANPATH}:";
    export INFOPATH="/opt/homebrew/share/info:${INFOPATH:-}";

    You probably need to modify pixi shell s.t. <pixi-env>/bin gets added to PATH as a last step, even after the rc file sourcing.

  3. changed the title [-]`pixi shell` has different PATH than `pixi run`[/-] [+]`pixi shell` has different PATH than `pixi run` when PATH gets modified in rc files[/+] on Aug 2, 2023
  4. ruben-arts commented on Aug 2, 2023

    @ruben-arts
    Contributor

    Thanks for the extended repro! This was indeed because the start script for pixi shell looks this if you're in bash:

    export PATH="/home/rarts/test/.pixi/env/bin:${PATH}"
    export CONDA_PREFIX="/home/rarts/test/.pixi/env"
    export PIXI_PACKAGE_MANIFEST="/home/rarts/test/pixi.toml"
    export PIXI_PACKAGE_PLATFORMS="linux-64"
    export PIXI_PROMPT="(test) "
    export PIXI_PACKAGE_VERSION="0.1.0"
    export PIXI_PACKAGE_ROOT="/home/rarts/test"
    export PIXI_PACKAGE_NAME="test"
    export CONDA_DEFAULT_ENV="test"
    bash

    Not really sure what the clean way go do this would be.

  5. baszalmstra commented on Aug 14, 2023

    @baszalmstra
    Contributor

    @pavelzw does the same thing happen when you use micromamba shell?

  6. pavelzw commented on Aug 14, 2023

    @pavelzw
    CollaboratorAuthor

    micromamba shell currently doesn't work at all for me 😅 it always drops me in the base environment. But even in base, this has the same issues. @jonashaag also checked out what nix does but they apparently seem to have the same problem.

    Maybe this could be an option? https://stackoverflow.com/a/36152028/18839600

    pixi shell = bash --rcfile <(echo '. ~/.bashrc; export PATH=<PIXI-stuff>:$PATH')
  7. baszalmstra commented on Aug 14, 2023

    @baszalmstra
    Contributor

    Haha wow, that looks super hacky! I like it!

    Is there something similar for zsh and other shells?

  8. pavelzw commented on Aug 14, 2023

    @pavelzw
    CollaboratorAuthor

    Seems to be shell specific. By playing around with zsh, I got this to work

    ZDOTDIR=$(mktemp -d) && echo '. ~/.zshrc; export PATH=abc:$PATH' > $ZDOTDIR/.zshrc && ZDOTDIR=$ZDOTDIR zsh
  9. ruben-arts commented on Aug 22, 2023

    @ruben-arts
    Contributor

    This is poetry's solution for this issue.

    I'm going to try to do this in our activation.

  10. baszalmstra commented on Aug 24, 2023

    @baszalmstra
    Contributor

    I created another issue that encapsulates all issues with our current solution and a way forward. Please follow that issue for progress!

  11. wolfv commented on Aug 25, 2023

    @wolfv
    Member

    I dug a little deeper into how poetry / pexpect and ptyprocess work.
    I think they are doing quite a lot more wrt to terminal emulation than rexpect (the Rust port of pexpect) does, especially in terms of how things like backspace etc. are handled. I might also have done things wrongly, I might need a night of sleep on it. But so far I am thinking we should first implement the "hacks" for bash & zsh (that we execute the activation script after sourcing the bashrc) and then later try more with rexpect.

  12. ruben-arts commented on Sep 29, 2023

    @ruben-arts
    Contributor

    This is fixed in #316.
    The pixi environment now gets activated after the shell is started thus overwriting the parts from your rc files.

    The repro now works if you build pixi in the docker container.
    Funnily enough that is what this example does so you can use that to test this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions