Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not change the PATH in deactivate.d/env_vars.sh script #13879

Open
2 tasks done
toihr opened this issue Apr 30, 2024 · 2 comments
Open
2 tasks done

Can not change the PATH in deactivate.d/env_vars.sh script #13879

toihr opened this issue Apr 30, 2024 · 2 comments
Labels
pending::feedback indicates we are waiting on feedback from the user source::community catch-all for issues filed by community members type::support neither a bug nor feature, is really just a user having questions or difficulty somewhere

Comments

@toihr
Copy link

toihr commented Apr 30, 2024

Checklist

  • I added a descriptive title
  • I searched open reports and couldn't find a duplicate

What happened?

I need to have a certain path added to my PATH environmental variable only whilst in a specific conda environment. I have added it as follows:

#!/bin/bash

export PATH=$PATH:/home/tihro/.miniforge3/envs/isis/bin

this adds the path to the variable without any problems. Now as the path is not important for other tasks, as it requires a set of other set environmental variables. I want to remove this on deactivation: Which i try to do as follows:

#!/bin/bash

tempPath=$(echo "$PATH" | tr ":" "\n" | grep -Fv "/home/tihro/.miniforge3/envs/isis/bin" | paste>

export test="$tempPath"
echo "doing something" #Check if something is actually done
export PATH="$tempPath"

When one now attempts to echo $PATH I will receive PATH still including the path i wanted to remove.
If i do echo $test I will obtain the collection of paths with the path removed.

I think this might be a bug with conda as it seems to work when executed as a normal bash file.

Conda Info

active environment : base
    active env location : /home/tihro/.miniforge3
            shell level : 3
       user config file : /home/tihro/.condarc
 populated config files : /home/tihro/.miniforge3/.condarc
          conda version : 24.1.2
    conda-build version : not installed
         python version : 3.10.14.final.0
                 solver : libmamba (default)
       virtual packages : __archspec=1=skylake
                          __conda=24.1.2=0
                          __cuda=12.4=0
                          __glibc=2.35=0
                          __linux=5.15.153.1=0
                          __unix=0=0
       base environment : /home/tihro/.miniforge3  (writable)
      conda av data dir : /home/tihro/.miniforge3/etc/conda
  conda av metadata url : None
           channel URLs : https://conda.anaconda.org/conda-forge/linux-64
                          https://conda.anaconda.org/conda-forge/noarch
          package cache : /home/tihro/.miniforge3/pkgs
                          /home/tihro/.conda/pkgs
       envs directories : /home/tihro/.miniforge3/envs
                          /home/tihro/.conda/envs
               platform : linux-64
             user-agent : conda/24.1.2 requests/2.31.0 CPython/3.10.14 Linux/5.15.153.1-microsoft-standard-WSL2 ubuntu/22.04.2 glibc/2.35 solver/libmamba conda-libmamba-solver/24.1.0 libmambapy/1.5.7
                UID:GID : 1000:1000
             netrc file : None
           offline mode : False

Conda Config

==> /home/tihro/.miniforge3/.condarc <==
channels:
  - conda-forge

Conda list

No response

Additional Context

No response

@toihr toihr added the type::bug describes erroneous operation, use severity::* to classify the type label Apr 30, 2024
@toihr
Copy link
Author

toihr commented Apr 30, 2024

Ok some additional information i just figured out, this seems to be a problem using zsh, if one does this in the bash this seems to work.

Addditionaly after some tinkering I did find that there is a problem with the env variable setting when one just calls conda deactivate this gives an error as follows:

(eval):unset:8: /home/tihro/Dropbox/masters_tom_ihro/Data/ISIS/: invalid parameter name

This error does not pop up when one does conda activate to return to base.

@travishathaway travishathaway added type::support neither a bug nor feature, is really just a user having questions or difficulty somewhere source::community catch-all for issues filed by community members and removed type::bug describes erroneous operation, use severity::* to classify the type labels May 2, 2024
@travishathaway
Copy link
Contributor

travishathaway commented May 2, 2024

Hi @toihr,

I played around with this a little myself and came up with the following...

All the paths you see below are relative to the conda installation directory.

envs/test-project/etc/conda/activate.d/env_vars.sh

Here's what my activate script looks like. It's inside an environment called "test-project":

CUSTOM_PATH=$HOME/apps/bin
export PATH="$PATH:$CUSTOM_PATH"

envs/test-project/etc/conda/deactivate.d/env_vars.sh

Here's the deactivate script that removes the custom path with sed.

CUSTOM_PATH="$HOME/apps/bin"
export PATH=$(echo $PATH | sed "s#:$CUSTOM_PATH##g")

This works for me on zsh. Let me know if this works for you.

Just FYI, this isn't an issue with conda. It's an error that is being raised during the shell scripts that were written.

@travishathaway travishathaway added the pending::feedback indicates we are waiting on feedback from the user label May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending::feedback indicates we are waiting on feedback from the user source::community catch-all for issues filed by community members type::support neither a bug nor feature, is really just a user having questions or difficulty somewhere
Projects
Status: 🆕 New
Development

No branches or pull requests

2 participants