Open jamesowers-cohere opened 7 months ago
you are effectively running the conda init section twice. just put the conda init portion in an else
guard, or restore your path afterward.
With apologies, I don't understand how I'm running the conda init section twice. I haven't additionally added the conda initialize
section - it only appears once in my ~/.bashrc (as expected). I mention it in the description such that you understand where I have added the code:
# Check if ORIGINAL_PATH is not set (first run) - this allows us to source this file multiple times
if [ -z "$ORIGINAL_PATH" ]; then
# Store the initial PATH
echo "Setting ORIGINAL_PATH to $PATH"
echo "This should only ever be done once upon shell startup"
# At time of writing, this was: /usr/local/bin:/usr/bin:/bin:/usr/games
export ORIGINAL_PATH=$PATH
fi
# Restore the initial PATH
export PATH=$ORIGINAL_PATH
i.e. above it.
How does my added code run conda init? all i'm doing is exporting the path...
ORIGINAL_PATH
is set have something about conda within it.export PATH=$ORIGINAL_PATH
. that in effect is running part of the conda initializationSo basically you are running part of the conda-initialization twice.
This isn't entirely the standard usecase.
What are you trying to preserve in your path?
original_path has nothing to do with conda in (it's as described in the comment) - i should highlight that it is only created once upon machine startup, since the if statement condition is false if original_path already exists. Also the issue I'm describing is that conda fails to get into my path if i do this.
To make this clearer, when i insert the path reset at to top of my bashrc, it has the affect of removing conda from my path (despite the fact that the conda init block is still in my bashrc after this path reset).
I'm trying to highlight that a user can do something valid in their bashrc and it can affect the conda installation.
I have updated the issue description to clarify all this and instructions about how to reproduce.
why do you think that your code should work in the first place? You are modifying the path in quite an intrusive way.
To debug try adding
env > env_before_conda_init.txt
# The conda init code
env > env_after_conda_init.txt
and inspect the differences if you want to force conda to rerun.
If i do this on my computer, I see:
CONDA_EXE
_CE_M
_CE_CONDA
CONDA_SHLVL
CONDA_PYTHON_EXE
PATH
all 6 are modified.
.bashrc
is only meant to be run once, during interactive sessions.
I'm not sure what your original usecase is, but I've never run accross the need to "reset" my original path the way you are doing now.
If you want to get really fancy, you can update the commands above during debugging to
env > env_before_$(date +%Y%m%d_%H%M%S_%N).txt
# ...
env > env_after_$(date +%Y%m%d_%H%M%S_%N).txt
Your debug will not work - it will be run after the first call of bashrc when I open an interactive terminal.
The reason i think it should work is documented in the description of the issue. Namely there's no issue for the other utils that alter my path!
Please may you try my instructions to reproduce the issue which I've provided in the description?
Solution to issue cannot be found in the documentation.
Issue
I am on Debian Linux. When inserted the following code into my ~/.bashrc at the top, whilst keeping the conda init section below, conda fails to make it onto my path:
If I remove this code, condabin is correctly added my PATH. If this code is inserted, conda does not update my PATH (although it duplicates some existing dirs in the path). What's going on here?
Note that:
~/.bashrc
is called for the very first time because ORIGINAL_PATH will exist upon second run, and the if condition will be false - the only effect will beexport PATH=$ORIGINAL_PATH
at the top of the file (and this condition should be identical to if this line was not there upon first run of~/.bashrc
)ORIGINAL_PATH
conda
which is affected.To reproduce this issue
echo $ORIGINAL_PATH
to verify conda is not there (this is expected and correct)echo $PATH
and note that:condabin
is not there (not expected, a bug)Issue also present on MacOS, so you can reproduce there, making edits to your ~/.zshrc instead.
Installed packages
Environment info