Can't run Anaconda in MacOS terminal - bash

I installed Anaconda on MacOS. I tried to run the conda command in terminal, but I got the following error message:
****/Users/rodalbert/.anaconda/navigator/a.tool ; exit;
/Users/rodalbert/.bash_profile:export:3: not an identifier: 2018.12
➜ ~ /Users/rodalbert/.anaconda/navigator/a.tool ; exit;
/Users/rodalbert/.anaconda/navigator/a.tool: line 1: syntax error near unexpected token `('
/Users/rodalbert/.anaconda/navigator/a.tool: line 1: `bash --init-file <(echo "source activate /Users/rodalbert/anaconda3;")'
[Process completed]****
I can't find the problem. Does someone know what to do in this case?
Content of .bash_profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
export PATH=/Applications/Postgres.app/Contents/Versions/11/bin/psql:$PATH# added by Anaconda3 2018.12 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
\eval "$__conda_setup"
else
if [ -f "/anaconda3/etc/profile.d/conda.sh" ]; then
. "/anaconda3/etc/profile.d/conda.sh"
CONDA_CHANGEPS1=false conda activate base
else
\export PATH="/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda init <<<
# added by Anaconda3 2018.12 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/Users/rodalbert/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
\eval "$__conda_setup"
else
if [ -f "/Users/rodalbert/anaconda3/etc/profile.d/conda.sh" ]; then
. "/Users/rodalbert/anaconda3/etc/profile.d/conda.sh"
CONDA_CHANGEPS1=false conda activate base
else
\export PATH="/Users/rodalbert/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda init <<<

It seems like you're using Zsh.
Before executing any command from within Anaconda Navigator, try opening your Terminal app and switching shell to bash: chsh -s /bin/bash then restart terminal.
After you're done with Anaconda, switch back to Zsh: chsh -s /bin/zsh then restart terminal.

I used MohammadChavos's solution, then conda can run on the terminal.
cd /path/to/anaconda/bin
./conda init zsh
or:
zsh conda init zsh
My case: cd opt/anaconda3/bin, then run: ./conda init zsh

Related

How to switch back and forth between pyenv python and system python in tmux?

My problem is almost identical to this question. However the solutions don't work when I use tmux. Usually I first open a terminal (bash) and then start a tmux session.
When I then try to use this solution:
in my ~/.bashrc I add
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('$HOME/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "$HOME/miniconda3/etc/profile.d/conda.sh" ]; then
. "$HOME/miniconda3/etc/profile.d/conda.sh"
else
export PATH="$HOME/miniconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
# Here comes the code to switch between conda and pyenv:
switch_pyenv(){
conda deactivate
conda deactivate # in case you're not in base env
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
}
switch_conda(){
conda activate base
export PATH="$HOME/miniconda3/bin:$PATH"
}
# quick check which python, pip
w(){
which python
which pip
python --version
}
However whenever I open tmux, the switching fails with the error message:
_pyenv_virtualenv_hook: command not found

How can I avoid typing the "source ~/.bash_profile" command in the terminal every time?

I just installed Anaconda. When I try to run a command, lets say conda --version, I get the following error message:
zsh: command not found: conda
When I type in:
source ~/.bash_profile
Everything works:
conda --version
conda 4.8.0
But I have to type the command every time I start the terminal.
My .bash_profile looks like this:
# added by Anaconda3 2019.10 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/Users/myusername/opt/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
\eval "$__conda_setup"
else
if [ -f "/Users/myusername/opt/anaconda3/etc/profile.d/conda.sh" ]; then
. "/Users/myusername/opt/anaconda3/etc/profile.d/conda.sh"
CONDA_CHANGEPS1=false conda activate base
else
\export PATH="/Users/myusername/opt/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda init <<<
What can I do to fix this?
System: macOS
place source ~/.bash_profile into ~/.zsh
Bash loads .bash_profile during init, for zsh it’s .zsh
Default shell was changed from bash to zsh with macOS Catalina, so that’s why there is the problem.

Anaconda installation modifying .bash_profile on Mac OS X

I installed Anaconda on my Mac (Mojave) and now whenever I start a shell it automatically activates the conda environment. This was totally fine until I realized some of the commands in my .bashrc were not being executed on startup. In particular, I had increased HISTSIZE and HISTFILESIZE but they always seemed to be stuck at their default values of 500. After some googling, I learnt that because of my anaconda installation, it was my .bash_profile that was being used on startup and not .bashrc. This is what my .bash_profile looks like (see below), just adding commands from my .bashrc file (e.g., HISTFILESIZE=100000) to the top of my .bash_profile appears to do nothing. Any suggestions on what I am doing wrong? Thanks!
# Setting PATH for Python 3.7
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
export PATH
# added by Anaconda3 2019.07 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
\eval "$__conda_setup"
else
if [ -f "/anaconda3/etc/profile.d/conda.sh" ]; then
# . "/anaconda3/etc/profile.d/conda.sh" # commented out by conda initialize
CONDA_CHANGEPS1=false conda activate base
else
\export PATH="/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda init <<<
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('//anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "//anaconda3/etc/profile.d/conda.sh" ]; then
. "//anaconda3/etc/profile.d/conda.sh"
else
export PATH="//anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
You can try to add the following lines in the bash_profile as suggested Here:
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi

Unexpected end of file - new to bash_profile

be kind I am very new to coding. I have an unexpected end of file in by bash_profile and I can't debug it. Would someone with more experience mind taking a look and help me get to the bottom of it?
# pipx
export PATH="~/.local/bin:$PATH"
# pyenv
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi
# poetry
export PATH="$HOME/.poetry/bin:$PATH"
# pip should only run if there is a virtualenv currently activated
export PIP_REQUIRE_VIRTUALENV=true
# commands to override pip restriction above.
# use `gpip` or `gpip3` to force installation of
# a package in the global python environment
# Never do this! It is just an escape hatch.
gpip(){
PIP_REQUIRE_VIRTUALENV="" pip "$#"
}
gpip3(){
PIP_REQUIRE_VIRTUALENV="" pip3 "$#"
}# added by Anaconda3 2019.07 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
\eval "$__conda_setup"
else
if [ -f "/anaconda3/etc/profile.d/conda.sh" ]; then
. "/anaconda3/etc/profile.d/conda.sh"
CONDA_CHANGEPS1=false conda activate base
else
\export PATH="/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda init <<<
I suggest to replace }# with } # in line 24.

zsh: command not found: react-native - MacOS

I am trying to start react-native but I get the following error zsh: command not found: react-native when I write react-native init firstApp
.
I tried the following guide: react-native: command not found
But I have two main issue:
First
I do not understand which path to use/export
React-native has been installed here:
/Users/cisco/.npm-packages/bin/react-native -> /Users/cisco/.npm-packages/lib/node_modules/react-native/local-cli/wrong-react-native.js
Second
In the guide it is written to run:
export PATH="/usr/local/Cellar/node/6.1.0/libexec/npm/bin:$PATH"
react-native init appName
cd appName
react-native run-ios
I do not get how to:
1) What to write after export PATH=
2) Should I add my path somewhere? If yes, how can I do so?
I tried running touch ~/.bash_profile; open ~/.bash_profile to add my path.
Inside it I have:
# added by Anaconda3 5.3.1 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
\eval "$__conda_setup"
else
if [ -f "/anaconda3/etc/profile.d/conda.sh" ]; then
. "/anaconda3/etc/profile.d/conda.sh"
CONDA_CHANGEPS1=false conda activate base
else
\export PATH="/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda init <<<
# added by Anaconda3 2018.12 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/Users/cisco/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
\eval "$__conda_setup"
else
if [ -f "/Users/cisco/anaconda3/etc/profile.d/conda.sh" ]; then
. "/Users/cisco/anaconda3/etc/profile.d/conda.sh"
CONDA_CHANGEPS1=false conda activate base
else
\export PATH="/Users/cisco/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda init <<<
Once you help me in finidng out the right path do add, can I simply add it in the file below the line # <<< conda init <<<?
Solved it!
Steps:
Run npm list -g | head -n 1
It will give you a path like/similar to the following: /Users/{YOUR_USER_NAME}/.npm-packages/lib
Change that path by substituting /lib with /bin:$PATH so that you get: /Users/cisco/.npm-packages/bin:$PATH
Run export PATH="/Users/{YOUR_USER_NAME}/.npm-packages/bin:$PATH"
Since you are using zsh. You can add export PATH=/Users/cisco/.npm-packages/bin/react-native:$PATH in ~/.zshrc
This operation work for me very well. Just follow the instruction below.
The default interactive shell is now zsh.
To update your account to use zsh, please run
chsh -s /bin/zsh

Resources