Closed jypeter closed 7 years ago
You could set their environment variable $PYTHONSTARTUP
to point to a file (/usr/local/blah) containing
import os
import subprocess
myEnv = os.environ.get("CONDA_DEFAULT_ENV",None)
preferedEnv = "cdatm15"
p = subprocess.Popen(["conda","env","list"],stdout = subprocess.PIPE)
o, e = p.communicate()
availableEnvs = [ x.split()[0] for x in o.split("\n")[:-2]][2:]
print "conda environments available:"," ".join(availableEnvs)
if myEnv is not None:
print "You are using the environment:",myenv
if myEnv != preferedEnv:
print "prefered environment is",preferedEnv
print "please run:"
print "source activate",preferedEnv
print "Get in touch with jypeter if you have problems/questions"
Which in my case would return:
conda environments available: 2.10 2.10-nox 2.10.copy 2.10.latest 2.10.nightly 2.10.nightly.mesa 2.8 2.8.latest VCDAT acme_diags_env mesa nightly-mesa p3 pmp_test py3 vcdat-version visus root
You are using the environment: 2.10.nightly.mesa
prefered environment is cdatm15
please run:
source activate cdatm15
Get in touch with jypeter if you have problems/questions
Note that for this to work as well with ipython you would have to symlink ${HOME}/.ipython
to the file that $PYTHONSTARTUP
point to
ln -s ${PYTHONSTARTUP} ${HOME}/.ipython
@jypeter another is to have a bash function that automatically picks the latest conda env for them:
function mostrecentdir {
DIRS=`ls -lrt $1 | awk '{print $9}'`
EXCLUDES=${@:2}
for EXCLUDE in $EXCLUDES
do
DIRS=`echo $DIRS | sed "s/${EXCLUDE}//g"`
done
echo `echo ${DIRS} | tr " " "\n" | tail -n1`
}
ANACONDA_HOME=${HOME}/anaconda2
setpy() {
if [ $# == 0 ]; then
pth=$(mostrecentdir ${ANACONDA_HOME}/envs _build)
else
pth=$1
fi
echo "Using "${pth}" conda environment"
source activate ${pth}
if [ `uname` == "Darwin" ]; then
export DYLD_FALLBACK_LIBRARY_PATH=${ANACONDA_HOME}/envs/${pth}/lib
fi
}
Thanks @doutriaux1 for all the leads! But I'd like something as lightweight as possible, and requiring little configuration in the users' environments
For now, I just have my users type, or add the following to their bashrc
# Initialize Miniconda
source ~jypeter/.conda_jyp.sh
and the content of _~jypeter/.condajyp.sh is
# Conda initialization by JYP
#
# Use this for working with conda and UV-CDAT centrally managed by JYP
#
# More details in:
# https://wiki.lsce.ipsl.fr/pmip3/doku.php/other:python:starting#conda-based_versions_of_uv-cdat
# https://wiki.lsce.ipsl.fr/pmip3/doku.php/other:uvcdat:conda_notes
#
# Jean-Yves Peterschmitt - LSCE - 03/2017
export PATH="/home/share/unix_files/cdat/miniconda2/bin:$PATH"
# Use the alias below to easily determine where your python
# interpreter is located
alias wp="which python"
# Where are ALL the python interpreters in the search path
alias wpa="which -a python"
# The end
If there is no existing way to have conda print a MOTD (just cat somefile) when people type source activate (that would be best), or for uvcdat python to do something similar at startup (without defining PYTHONSTARTUP), I can probably just add some echo lines to the _condajyp.sh I have people execute
The only way would be to create a conda package for this. conda packages can extend source activate
Good to know, thanks! But quite an overkill for what I need Now I have to (find time to) experiment
Does anybody know if there is a way to automatically print a MOTD when people:
I maintain a mutli-user uvcdat (several versions used by several people) on our servers, and it would be convenient to be able to use a MOTD to give people some basic information/hints, e.g. to tell people about the latest installed version.