Terminal Start up issue - bash

I want to speed up my terminal's load process because when I start it up it starts to run a something, and when I try to close the window it gives me this https://i.stack.imgur.com/8xkWW.png which means that it might have to do bash profile which is:
# Setting PATH for Python 2.7
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH
# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH
# 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
# 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 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 <<<
alias py="python"
alias cdpy="cd /Users/Sqirel4x2/BitsBobs/Coding/python"
alias editpro="sudo nanos ~/.bash_profile"
If anyone could help speed up my terminal load then that would be great.

What sped up my load speed was deleting Anaconda to test your time do: time bash start to troubleshoot this problem look at your bash profile by: sudo nano .bash_profile and then see what happens before you load up terminal.

Related

Editing .bash_profiles with conda installed

I am trying to follow along with a book that for some of the chapters requires the line
export PATH="$PATH:$HOME/scripts"
be added to a .bash_profiles in the home directory. Probably, after peaking later in the book it is to launch scripts located in that folder quickly from the terminal without specification of path of that file, it seems useful so I would like to do it.
Although, since I have previously installed conda on my mac, it apparently changed something and addition of that line did not alter the output of echo $PATH
.bash_profiles looks now 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/eshauchuk/opt/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
\eval "$__conda_setup"
else
if [ -f "/Users/eshauchuk/opt/anaconda3/etc/profile.d/conda.sh" ]; then
. "/Users/eshauchuk/opt/anaconda3/etc/profile.d/conda.sh"
CONDA_CHANGEPS1=false conda activate base
\export PATH="$PATH:$HOME/scripts"
else
\export PATH="/Users/eshauchuk/opt/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
export PATH="$PATH:$HOME/scripts"
# <<< conda init <<<
I have added the mentioned line to the near end of the .bash_profile now and also went to the found in this files conda files to try add it there with no change for now.
What can I do to make it work
Check this comment:
# !! Contents within this block are managed by 'conda init' !!
So try to put your line after the block like this:
# <<< conda init <<<
export PATH="$PATH:$HOME/scripts"

conda activate command not working on mac

I have miniconda 4.8.3 + MacOS Catalina 10.15. I can manually activate the conda environment in the terminal and start a spyder session.
$ ~/miniconda3/bin/conda activate py3
$ ~/miniconda3/bin/conda info | grep "active environment"
$ spyder &
When I put the above in a script, run_spyder.sh it's not working, and it complains about "CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'."
#!/bin/bash
# run_spyder.sh
~/miniconda3/bin/conda activate py3
~/miniconda3/bin/conda info | grep "active environment" # still print base
# spyder &
I tried alternatives like bash -i ./run_spyder.sh, or source ./run_spyder.sh, or adding ~/miniconda3/bin/conda init bash, none of them work.
Shell is still bash, no .bashrc, in .bash_profile this is the script automatically generated by miniconda installation
# .bashrc_profile
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('~/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "~/miniconda3/etc/profile.d/conda.sh" ]; then
. "~/miniconda3/etc/profile.d/conda.sh"
else
export PATH="~/miniconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
The conda activate function is a shell function that is typically defined in the initialization file for a shell when the session starts (e.g., in the .bash_profile). The conda init function merely adds code to such initialization files, but will not actually source the code it adds. Hopefully, that clarifies the difficulty with what was tried in the question (and comments).
Instead, try directly sourcing the code that Conda uses. Something like:
#!/bin/bash
source ~/miniconda3/etc/profile.d/conda.sh
conda activate py3
conda info | grep "active environment"
spyder &
Another option is to have the bash (or zsh) session launch in login mode (i.e., runs the initialization files for the current user).
#!/usr/bin/env bash -l
conda deactivate # <- may not be needed, but didn't work for me without
conda activate py3
conda info | grep "active environment"
spyder &
However, note that in this latter case I find I need to include a conda deactivate first, in order for the conda activate to properly prioritize the Python in the env on PATH.

Calling An Anaconda Environment from MATLAB: Conda Command Not Found

I want to call a Python script I created in its own Anaconda environment and wanted to call the script from Matlab 2020a. However, when I try to activate the environment from Matlab, I get an error message:
system('conda activate *name_of_environment*')
/bin/bash: conda: command not found
I installed the newest version of anaconda3 (2020.02) on a Ubuntu 18.04 machine and, as recommended, didn't add conda to bashrc but added the conda.sh directory instead as recommended here:
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/michael/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/home/michael/anaconda3/etc/profile.d/conda.sh" ]; then
. "/home/michael/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/home/michael/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
# export PATH="/home/michael/anaconda3/bin:$PATH" # commented out by conda initialize
#Enable conda to be called from bash
source /home/michael/anaconda3/etc/profile.d
However, I can't find an explanation how to run conda from Matlab otherwise. Am I missing something?
Thanks a bunch, and best,
Michael
Let me elaborate my comment it in an answer.
Binaries are found trough the PATH environment variables. The location of conda is not in that variable. Therefore you should either add it to your PATH variables (or un-comment it that script at your notification).
Example:
$ export PATH="$PATH:/home/michael/anaconda3/bin/"
$ ./yourscript.sh
But it also can be that the PATH variable isn't copied through system(), which I guess executes the script in a new shell. In this case, you should execute it as:
system('/home/michael/anaconda3/bin/conda activate *name_of_environment*')
I know it is too late, but maybe the best way to run a python script using a conda environment is to call the python executable associated with that environment directly:
system('~/anaconda3/envs/<name_of_environment>/bin/python your_script.py')

Adding conda to the PATH on macos Catalina

I downloaded the Anaconda individual edition 2020-2 graphical installer. And then by using the graphical wizard I installed Anaconda successfully in my macbook. I checked this by running the command conda --version it was giving the result of conda 4.8.2.
Next day when I opened the terminal and tried executing conda commands surprisingly I was getting command not found error. I checked the PATH by executing echo$PATH and found that Anaconda directory is not included in the path. I tried to add anaconda by running the following command:
export PATH="usr/local/bin:usr/bin:/bin:usr/sbin:/sbin:/opt/anaconda3/bin"
After this conda commands were working on the same session but it was not when a new terminal window was opened.
To fix this I opened the .bash_profile file in my home directory in vi editor and found that the following lines were already there in the file:
bash-3.2$ cat .bash_profile_bk
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/opt/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/opt/anaconda3/etc/profile.d/conda.sh" ]; then
. "/opt/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/opt/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
So I renamed the file to .bash_profile_bk by the following command
$mv .bash_profile .bash_profile_bk
Then created a new .bash_profile and added the export PATH line as follows
$vi .bash_profile
in vi editor:
export PATH="usr/local/bin:usr/bin:/bin:usr/sbin:/sbin:/opt/anaconda3/bin"
I checked the content of the file:
bash-3.2$ cat .bash_profile
export PATH="/usr/bin:usr/local/bin:/bin:usr/sbin:/sbin:/opt/anaconda3/bin"
exit the terminal session and then opened another terminal window. Typed the conda command but again it was not working:
bash-3.2$ conda --version
bash: conda: command not found
Can somebody suggest if I'm missing something? any help will be greatly appreciated.

I have broken my PATH on bash_profile and nothing works, can't even launch Jupyter notebook

Here's the response I keep getting whenever I try to launch Jupyter notebook:
Users-MacBook:~ user$ jupyter notebook
-bash: jupyter: command not found
And these are the current content of my .bash_profile:
# added by Anaconda3 2018.12 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/Users/user/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH"
export PATH
export PATH
if [ $? -eq 0 ]; then
\eval "$__conda_setup"
else
if [ -f "/Users/user/anaconda3/etc/profile.d/conda.sh" ]; then
. "/Users/user/anaconda3/etc/profile.d/conda.sh"
CONDA_CHANGEPS1=false conda activate base
else
\export PATH="/Users/user/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda init <<<
Am really frustrated by it. Can I rewrite the bash_profile again or could I just download the .bash_profile somewhere; that means I would have to copy it from someone. I've not found anything anywhere.
Rename your .bash_profile to something else so it won't mess with your console. To remove it use the full path in command, for example
/bin/mv ~/.bash_profile ~/bad_bash_profile
Then your next new session will start with whatever is default for all users and you can check what's wrong and fix it.
If you want more info on what's wrong, please post the contents of your $PATH variable as commented by glenn jackman.

Resources