How to temporarily escape anaconda/conda shell environment - anaconda

Once you've installed anaconda/conda, and configured your shell init file to set the path, how can you temporarily escape from that environment to use the system tools, for example the version of python that was installed natively?

If you did a default install and, therefore, followed the best practice configuration introduced in Conda v.4.4, then it is simply a matter of deactivating the base env:
conda deactivate

merv's answer is better...
Here is a way to do this on the fly without editing one's init files:
(base) ➜ ~ which python
/home/xxx/anaconda3/bin/python
(base) ➜ ~ echo $PATH
/home/xxx/anaconda3/bin:/home/xxx/anaconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
(base) ➜ ~ export PATH=$(echo ${PATH} | awk -v RS=: -v ORS=: '/conda/ {next} {print}' | sed 's/:*$//')
(base) ➜ ~ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
(base) ➜ ~ which python
/usr/bin/python
(base) ➜ ~

Related

Git Bash | bash: sudo: command not found (and others)

Goal: get Poetry working.
Using Git Bash on Windows 10 with WSL 2.
I have Anaconda3 and Git working.
pip install bash worked but did not help.
Git Bash:
(base)
HDS+dabell#PF2DCSXD MINGW64 ~
$ sudo -s
bash: sudo: command not found
(base)
HDS+dabell#PF2DCSXD MINGW64 ~
$ su -
bash: su: command not found
(base)
HDS+dabell#PF2DCSXD MINGW64 ~
$ apt update
bash: apt: command not found
(base)
HDS+dabell#PF2DCSXD MINGW64 ~
$ apt install sudo -y
bash: apt: command not found
(base)
HDS+dabell#PF2DCSXD MINGW64 ~
$ cat ~/.bashrc
. /c/Users/dabell/Anaconda3/etc/profile.d/conda.sh
(base)
These commands work in WSL 2.
As stated by #tkausl, Git Bash does not come with such commands.
I've also found a similar post on Stack Overflow, the top answer stating the same.

.zshenv:2: command not found: rbenv error

ive been trying to load ruby on my macOs Big Sur and i cannot for the life of me figure out how to fix this
i was trying to install cocoapods when it gave me this error so i follwed this instruction and im now getting this error \
/Users/kashish/.zshrc:103: command not found: rbenv
➜ ~ export PATH=/usr/local/bin:$PATH
➜ ~ which rbenv
rbenv not found
➜ ~ export PATH=/usr/local/bin:$PATH
➜ ~ rbenv doctor
zsh: command not found: rbenv
➜ ~ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshenv
echo 'eval "$(rbenv init - zsh)"' >> ~/.zshenv
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.zshenv
➜ ~ rbenv doctor
zsh: command not found: rbenv

'scl enable' not setting PATH with bash

I'm trying to use software collections on CentOS 6.8 server, but it won't set the environment variable PATH corectly if the command passed is "bash", but "tcsh" works... (however we don't use tcsh on this machine)
Example:
$ scl --list
devtoolset-4
python27
rh-java-common
rh-perl524
rh-python35
$ which python
/usr/bin/python
$ python --version
Python 2.6.6
$ scl enable python27 bash
$ which python
/usr/bin/python
$ python --version
Python 2.6.6
$ cat /opt/rh/python27/enable
export PATH=/opt/rh/python27/root/usr/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/opt/rh/python27/root/usr/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export MANPATH=/opt/rh/python27/root/usr/share/man:${MANPATH}
# For systemtap
export XDG_DATA_DIRS=/opt/rh/python27/root/usr/share:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}
# For pkg-config
export PKG_CONFIG_PATH=/opt/rh/python27/root/usr/lib64/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}
$ echo $PATH
/usr/share/gridengine/bin/lx26-amd64:/usr/lib64/qt-3.3/bin:/usr/NX/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/bin:/opt/maker/bin:/opt/tools/:/opt/tools/amos-3.1.0:/opt/mpich-install/bin:/opt/pssc/bin:/opt/torque/bin:/opt/torque/sbin
$ echo $LD_LIBRARY_PATH
/opt/rh/python27/root/usr/lib64
$ echo $MANPATH
/opt/rh/python27/root/usr/share/man::/opt/mpich-install/share/man:/opt/mpich-install/share/man
So why is MANPATH and LD_LIBRARY_PATH being set properly but not PATH? If i use tcsh it works as expected:
$ scl enable python27 tcsh
$ which python
/opt/rh/python27/root/usr/bin/python
$ python --version
Python 2.7.8
Thank you Dominic you were on to something. I originally checked ~/.bash* files as well as /etc/bash* and /etc/profile but after your comment, I found several scripts in /etc/profile.d/ that we being executed, and one of them set the PATH explicitly without appending. I added $PATH back in there and now scl enable is working as expected!

Why do I need to add ~/.rbenv/bin to my path?

I read in rbenv can't change global ruby version that I need to add ~/.rbenv/bin to my PATH for rbenv to work.
That's also mentioned in the rbenv documentation but that directory doesn't exist as shown below:
$ ls -a ~/.rbenv/
. .. plugins shims version versions
So why do I need to add a directory that doesn't exist to my path for rbenv to work?
Edit:
#theTinMan, I tried uninstall and reinstalling, but I still don't have a ~/.rbenv/bin path. Where are you seeing in the documentation that it should be there?
$ rbenv --version
rbenv 1.0.0
$ which rbenv
rbenv () {
local command
command="$1"
if [ "$#" -gt 0 ]
then
shift
fi
case "$command" in
(rehash | shell) eval "$(rbenv "sh-$command" "$#")" ;;
(*) command rbenv "$command" "$#" ;;
esac
}
$ cd
$ ls .rbenv
plugins shims version versions
$ brew list | grep rbenv
rbenv
$
$ brew uninstall rbenv
Uninstalling /usr/local/Cellar/rbenv/1.0.0... (36 files, 61.9K)
rbenv 0.4.0 is still installed.
Remove all versions with `brew uninstall --force rbenv`.
$ brew uninstall --force rbenv
Uninstalling rbenv... (32 files, 49.9K)
$ brew install rbenv
==> Summary
🍺 /usr/local/Cellar/rbenv/1.0.0: 36 files, 62K
$ ls .rbenv
plugins shims version versions
$ rbenv -v
rbenv 1.0.0
$ rbenv versions
system
2.0.0-p648
* 2.3.1 (set by /Users/max/.rbenv/version)
$
I had the following in my .zshrc
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
But I only needed the bottom line
# export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

`command -v` seems to only search in /usr/bin

For some shell script I need to store output of command -v foo in variables. I am checking if some binaries exist on the system. When I execute command -v foo in terminal, I get an output but when I execute command -v foo inside a shell script I don't get any output.
➜ tools git:(install-script) ✗ command -v node
/usr/local/bin/node
check_deps() {
declare -A deps
deps=( ['git']=`command -v git`
['gem']=`command -v gem`
['node']=$(command -v node))
# ['redis-server']=command -v redis-server
# ['postgres']=command -v psql
# ['sass']=command -v sass
# ['gulp']=command -v gulp
# ['bower']=command -v bower )
for each in ${!deps[#]};
do
echo $each ${deps[$each]}
done
}
check_deps
Output is:
node
git /usr/bin/git
gem /usr/bin/gem
[Finished in 0.0s]
What's happening? How do I fix this?
I was using Sublime Text which had a plugin called Bash Build system. Basically it got me a file which didn't have /usr/local/bin, this build syntax now returns proper command -v output:
{
"cmd" : ["bash", "$file"],
"selector" : "source.shell",
"osx": {
"path" : "$PATH:/usr/local/bin"
}
}

Resources