Failing in Install Anaconda in C-shell - shell

My shell is C shell, I cannot initial and activate conda environment, The following is what happens when I run conda activate:
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.

In your shell, execute the command:
conda init bash
I am assuming your shell name is bash. If not use it as per your shell.
Currently supported shells are:
- bash
- fish
- tcsh
- xonsh
- zsh
- powershell

Related

switch between different conda environments in bash

In the part of my bash script I need to switch to specific conda environment to use package that had been installed specifictly in this environment:
#!/bin/bash
home="$PWD"
# activate VINA 1.2.3
conda activate vina
vina --some_in --some_out
# go back to default environment
conda deactivate
While this works fine simply in the terminal (I am using MacOSX) the sh script executing the same commands produces the following errors:
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run
$ conda init <SHELL_NAME>
Currently supported shells are:
- bash
- fish
- tcsh
- xonsh
- zsh
- powershell
I've tried to use
conda init bash && conda deactivate
which works fine in the terminal but did not solve the problem in the sh script
How I could properly switch between different conda environemnts in the SH script ?

'Conda activate base' fails to load when executed from Matlab on Ubuntu (18.04). Error: conda: command not found

My Conda working perfectly from the ubuntu terminal. I can easily activate the environment I need using the following command
$ conda activate base
and it loads the base environment on the terminal.
But here, in MATLAB, when I try to activate conda environment using the following command it returns an error
>> system('conda activate base')
/bin/bash: conda: command not found
Based on other posts with similar discussions, I have tried the following but to no luck
>> system('/home/anirudha/anaconda3/bin/conda activate base')
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run
$ conda init <SHELL_NAME>
Currently supported shells are:
- bash
- fish
- tcsh
- xonsh
- zsh
- powershell
See 'conda init --help' for more information and options.
IMPORTANT: You may need to close and restart your shell after running 'conda init'.
>> system('conda init bash');
/bin/bash: conda: command not found
I have also tried solutions from this but to no success again.
My purpose is to execute a few gdal functions from the command line through a MATLAB script. I have tried doing this on my windows PC, and everything works perfectly. But not on my Linux station. Am I missing something?

anaconda: could not use shell script to switch environment

I have anaconda installed. I am using centOS 8.2, anaconda installation package name is: Anaconda3-2020.11-Linux-x86_64.sh ,
With the initialization, the environment is base. as it shows in the following command line:
(base) [sjj#localhost ~]$
I wrote a shell script named as env.sh as follows, the purpose it to switch environment:
#!/bin/sh
conda activate ray-tutorial
It always say:
(base) [sjj#localhost ~]$ sh env.sh
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run
$ conda init <SHELL_NAME>
Currently supported shells are:
- bash
- fish
- tcsh
- xonsh
- zsh
- powershell
See 'conda init --help' for more information and options.
IMPORTANT: You may need to close and restart your shell after running 'conda init'.
But if I directly type the command to switch the environment, it works: My question is why shell script does not work in this case?
(base) [sjj#localhost ~]$ conda activate ray-tutorial
(ray-tutorial) [sjj#localhost ~]$

Activate conda environment within a new xterm terminal

If I run
xterm -hold
and within the new terminal I type
conda activate my_environment
the conda environment "my_environment" is indeed activated.
However, when passing this command using the -e flag, it does not work:
xterm -hold -e "conda activate my_environment"
It instead returns the following error message:
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run
$ conda init <SHELL_NAME>
Currently supported shells are:
- bash
- fish
- tcsh
- xonsh
- zsh
- powershell
See 'conda init --help' for more information and options.
IMPORTANT: You may need to close and restart your shell after running 'conda init'.
So, how can this be done using xterm? Or should I use another type of external terminal?
Background
The conda activate command is a shell function that gets defined during initialization of the shell. conda init adds code to the initialization file (e.g., .bash_profile) to run the scripts that define the conda activate shell function.
Solutions
Possible fix: xterm options
When using the -c argument with xterm it no longer runs the initialization script. Hence, conda activate never gets defined. For bash there is the -l that tells it to run the init files. I expected xterm's -ls argument to trigger similar behavior, but it didn't work for me. Perhaps someone more familiar can point you to the correct flag.
Manually Run Conda Script
Otherwise, you just run the Conda script yourself (assuming it's the bash version). Either of these will work:
xterm -hold -e ". /path/to/miniconda3/etc/profile.d/conda.sh && conda activate my_environment && which python"
or
xterm -hold -e "$(conda shell.bash hook) && conda activate my_environment && which python"
The which python is only included to show that you're getting the env activated.
Conda Run
Another option is conda run, which automates executing commands under an environment. The follow is equivalent to what I did in the last section, but without having to know what shell I am running in:
xterm -hold -e "conda run -n my_environment which python"
Just be aware that this functionality is still a work-in-progress. Personally, I've found it quite useful for running simple scripts in specific envs and haven't run into problems.

Failed to activate virtualenv via shellscript

I'm trying to activate my pyenv-virtualenv environment through very simple bash script like this.
set -e
pyenv activate myenv
But I can't activate my env with below error:
Failed to activate virtualenv.
Perhaps pyenv-virtualenv has not been loaded into your shell properly.
Please restart current shell and try again.
I can activate it in command line, so I think it's due to my shell environment.
I use fish shell, but it's launched after $PATH settings read in bash shell.
I show you my settings.
.bash_profile:
export LANG="ja_JP.UTF-8"
export XDG_CONFIG_HOME="$HOME/.config"
export PATH="/sbin"
export PATH="/usr/sbin:$PATH"
export PATH="/bin:$PATH"
export PATH="/usr/bin:$PATH"
export PATH="/usr/local/bin:$PATH"
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
exec fish
And my config.fish:
status --is-interactive; and source (pyenv init -|psub)
status --is-interactive; and source (pyenv virtualenv-init -|psub)
What's wrong?
I'm using:
OS: OS X 10.13.5
fish: v2.7.1
pyenv: v1.2.5
pyenv-virtualenv: v1.1.3
I believe the cause is that you are initializing PyEnv in the Fish shell environment but then calling PyEnv in the Bash shell environment (via your Bash script). To solve this problem, you could try either of the following potential solutions:
Initialize PyEnv in your Bash environment (in addition to your Fish environment)
Write your script in Fish instead of Bash
Since PyEnv seems so have better support for Bash than Fish, let's focus on option #1. Step 3 of the PyEnv installation guide suggests the following command for adding PyEnv initialization to your ~/.bash_profile:
$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bash_profile
After running that command, I suspect your script will function as you expect. If it does not, you could try adding the same PyEnv initialization snippet (that you just added to your ~/.bash_profile) to the top of your Bash script.

Resources