How to install Anaconda python for all users?
Question:
Anaconda python distribution is very convenient to deploy scientific computing env (SCE) and switch python versions as you want. By default, the installation will locate python into ~/anaconda
and the SCE can only benefit the local user.
But what I need is to provide a complete SCE wit Anaconda while masking the system-wide python version, because my cluster is running Spark and provides services for multiple users in our team. Is it possible with current Anaconda version?
Xiaming
Answers:
Anaconda Cluster from Continuum that addresses these issues. Check out https://docs.continuum.io/anaconda-scale/
The installer lets you install anywhere. You can install it to a global location, like /opt/anaconda
.
Add the anaconda PATH to /etc/profile
:
for anaconda 2 :
PATH=$PATH:$HOME/anaconda/bin
for anaconda 3 :
PATH=$PATH:$HOME/anaconda3/bin
and then :
source /etc/profile
You definitely need to install to a path which is accessible from all users. /opt/YOUR_CONDA_DISTRIB_NAME
is a good candidate.
However you also have to add conda
path which automatically happens when you add the following shell script to other users’ .bashrc
files. You can find the shell script in the root user’s .bashrc
file. For the record, I bring it here:
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/opt/YOUR_CONDA_DISTRIB_NAME/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/opt/YOUR_CONDA_DISTRIB_NAME/etc/profile.d/conda.sh" ]; then
. "/opt/YOUR_CONDA_DISTRIB_NAME/etc/profile.d/conda.sh"
else
export PATH="/opt/YOUR_CONDA_DISTRIB_NAME/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
P.S. a few common names which Anaconda commonly uses for YOUR_CONDA_DISTRIB_NAME
:
anaconda
anaconda3
miniconda
miniconda3
You can also let any user who needs conda run the conda init
command to automatically let conda update their .bashrc so they will be able to use the conda environment. For example in linux if anaconda is installed in /opt/anaconda3:
$ /opt/anaconda3/bin/conda init
no change /opt/anaconda3/condabin/conda
no change /opt/anaconda3/bin/conda
no change /opt/anaconda3/bin/conda-env
no change /opt/anaconda3/bin/activate
no change /opt/anaconda3/bin/deactivate
no change /opt/anaconda3/etc/profile.d/conda.sh
no change /opt/anaconda3/etc/fish/conf.d/conda.fish
no change /opt/anaconda3/shell/condabin/Conda.psm1
no change /opt/anaconda3/shell/condabin/conda-hook.ps1
no change /opt/anaconda3/lib/python3.9/site-packages/xontrib/conda.xsh
no change /opt/anaconda3/etc/profile.d/conda.csh
modified /home/my.userid/.bashrc
==> For changes to take effect, close and re-open your current shell. <==
Anaconda python distribution is very convenient to deploy scientific computing env (SCE) and switch python versions as you want. By default, the installation will locate python into ~/anaconda
and the SCE can only benefit the local user.
But what I need is to provide a complete SCE wit Anaconda while masking the system-wide python version, because my cluster is running Spark and provides services for multiple users in our team. Is it possible with current Anaconda version?
Xiaming
Anaconda Cluster from Continuum that addresses these issues. Check out https://docs.continuum.io/anaconda-scale/
The installer lets you install anywhere. You can install it to a global location, like /opt/anaconda
.
Add the anaconda PATH to /etc/profile
:
for anaconda 2 :
PATH=$PATH:$HOME/anaconda/bin
for anaconda 3 :
PATH=$PATH:$HOME/anaconda3/bin
and then :
source /etc/profile
You definitely need to install to a path which is accessible from all users. /opt/YOUR_CONDA_DISTRIB_NAME
is a good candidate.
However you also have to add conda
path which automatically happens when you add the following shell script to other users’ .bashrc
files. You can find the shell script in the root user’s .bashrc
file. For the record, I bring it here:
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/opt/YOUR_CONDA_DISTRIB_NAME/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/opt/YOUR_CONDA_DISTRIB_NAME/etc/profile.d/conda.sh" ]; then
. "/opt/YOUR_CONDA_DISTRIB_NAME/etc/profile.d/conda.sh"
else
export PATH="/opt/YOUR_CONDA_DISTRIB_NAME/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
P.S. a few common names which Anaconda commonly uses for YOUR_CONDA_DISTRIB_NAME
:
anaconda
anaconda3
miniconda
miniconda3
You can also let any user who needs conda run the conda init
command to automatically let conda update their .bashrc so they will be able to use the conda environment. For example in linux if anaconda is installed in /opt/anaconda3:
$ /opt/anaconda3/bin/conda init
no change /opt/anaconda3/condabin/conda
no change /opt/anaconda3/bin/conda
no change /opt/anaconda3/bin/conda-env
no change /opt/anaconda3/bin/activate
no change /opt/anaconda3/bin/deactivate
no change /opt/anaconda3/etc/profile.d/conda.sh
no change /opt/anaconda3/etc/fish/conf.d/conda.fish
no change /opt/anaconda3/shell/condabin/Conda.psm1
no change /opt/anaconda3/shell/condabin/conda-hook.ps1
no change /opt/anaconda3/lib/python3.9/site-packages/xontrib/conda.xsh
no change /opt/anaconda3/etc/profile.d/conda.csh
modified /home/my.userid/.bashrc
==> For changes to take effect, close and re-open your current shell. <==