Conda - dwisianto/dwisianto GitHub Wiki

Routine1

conda info
conda clean --all
conda search -f <myPackage>
conda config --set auto_active_base false

Routine2

- conda create --name <myEnv> --clone base
- conda create --name <myEnv> python==3.9
- conda install -y -c conda-forge pydantic
- conda env export --from-history > environment.yml
- conda env create --name envname --file=environments.yml

Routine3

export SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt
export REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-bundle.crt
export PIP_DEFAULT_TIMEOUT=1000

Duplicate

would recommend that you try the method as shown on this official documentation. In summary, you can get all the list of modules installed in the virtual environment, save it as a .txt file, and create a new environment from that .txt file. For example,

conda list --explicit > spec-file.txt Then, create a new environment using that specification.

conda create --name myenv --file spec-file.txt While this is not exactly "cloning" the base environment, you should be able to reproduce a virtual environment identical to the base through this process.

Share

Configuration

  • Disable Base Env
  • conda config --set auto_activate_base false
  • conda config email
  • conda config username

Miniforge

Duplication Script

ana_id='og22dash3'


#
#
#
reset_=(
  "conda env remove --name ${ana_id}"
)
reset() {
  nm1=${FUNCNAME[0]}
  nm0=${nm1:0:1} # first character
  # echo "#" $nm0 - $nm1 - "$@"

  case "$@" in
    ${nm0} | ${nm1} )
      echo "${reset_[0]}"
    ;;
    ${nm0}- | ${nm1}- )
      ${reset_[0]}
    ;;
  esac
}


#
# Anaconda environment
#
start_sc0="conda create  --name=${ana_id} -y python==3.9"
start_sc1="conda install --name=${ana_id} -y -c conda-forge "
start_=(
  "${start_sc0}"
  "${start_sc1} dash pandas numpy matplotlib Werkzeug"
  "${start_sc1}"
)

start() {
  nm1=${FUNCNAME[0]}
  nm0=${nm1:0:1} # first character

  case "$@" in
    ${nm0} | ${nm1} )
      for i in {0..1}
      do
        echo " # ${start_[$i]} "
      done
    ;;
    ${nm0}- | ${nm1}- )
      for i in {0..1}
      do
        ${start_[$i]}
      done
    ;;
  esac
}

#
# Duplicate
#
d_0="${ana_id}.env.yaml"
d_1="conda env export --name=${ana_id} --from-history "
duplicate_=(
  "${d_0}"
  "${d_1}"
)
duplicate() {
  nm1=${FUNCNAME[0]}
  nm0=${nm1:0:1} # first character

  case "$@" in
    ${nm0} | ${nm1} )
      echo " ${duplicate_[1]}"
      echo " ${duplicate_[0]}"
    ;;
    ${nm0}- | ${nm1}- )
      echo "# ${duplicate_[1]}"
      echo "# ${d_0}"
      ${duplicate_[1]} > ${d_0}
      echo "# Done"
    ;;
  esac
}


#
#
#
c_1="conda env create --name ${ana_id} --file=${d_0}"
create_=(
  "${c_1}"
)
create() {
  nm1=${FUNCNAME[0]}
  nm0=${nm1:0:1} # first character

  case "$@" in
     ${nm1} | ${nm0} )
      echo "# ${nm0} : ${nm1} "
      echo "# ${d_0}"
      if [ -e ${d_0} ];
        then
          echo "# File exists: ${d_0} "
        else
          echo "# File missing: ${d_0} "
      fi
      echo "${create_[0]}"
    ;;
    ${nm1}- | ${nm0}- )
      ${create_[0]}
    ;;
  esac
}

#
#
#
act() {
  reset "$@"
  start "$@"
  duplicate "$@"
  create "$@"
}
act "$@"

JupyterLab

https://stackoverflow.com/questions/67202874/what-is-nb-conda-kernels-equivalent-for-python-3-9 https://stackoverflow.com/questions/67210097/is-it-advisable-to-not-mix-packages-in-a-conda-environment-from-different-conda https://stackoverflow.com/questions/62526717/error-package-or-namespace-load-failed-for-rjags

  1. Conda
# create environment only from Conda Forge
conda create -n jpl39a --override-channels -c conda-forge jupyter jupyterlab nb_conda_kernels python=3.9 -y

# activate
conda activate -n jpl39a

# set env-specific channel options
conda config --env --set channel_priority strict
conda config --env --add channels conda-forge

jupyter notebook --generate-config
  1. install nb_conda_kernels in your base environment. Once this is installed any notebook running from the base environment will automatically show the kernel from any other environment which has ipykernel installed.
(base)$ conda install nb_conda_kernels
  1. Next, create a new environment. I will call mine new-env. If you already have an environment you are trying to get to show on Jupyter Notebook, skip this step.
(base)$ conda create --name new-env
  1. Activate the environment you want to use in your notebook and install iypkernel. My environment is called new-env. If you already have an environment substitute your environment nane for new-env
(base)$ conda activate new-env
(new-env)$ conda install ipykernel
  1. Restart Jupyter Notebooks from your base environment and done. You can see here that all of my environments with ipykernel installed including new-env are showing. I can now switch between them at will. Bliss.

Env

ie39

conda create --name ie39 --clone base
conda install pytest pytest-order

Jupyter

conda install -c conda-forge jupyter, 
jupyter_contrib_nbextensions
jupyter notebook

JupyterLab

conda install -c conda-forge jupyterlab

First, install nb_conda_kernels in your base environment. Once this is installed any notebook running from the base environment will automatically show the kernel from any other environment which has ipykernel installed.

(base)$ conda install nb_conda_kernels

Activate the environment you want to use in your notebook and install iypkernel. My environment is called new-env. If you already have an environment substitute your environment nane for new-env

(base)$ conda activate new-env
(new-env)$ conda install ipykernel

Jupyter Method 2: “The Usual Way”

It is not that much harder to individually register each environment you want to show in your kernels list. If you have many environments this might be preferable because it allows you to register and un-register your environment kernels which could help keep that list tidy.

In your new environment install ipykernel

(new-env)$ conda install ipykernel
  1. Register the kernel spec with Jupyter using the following command. The--name= argument will set the name you see in Jupyter Notebooks for this environment’s kernel (so you can call it whatever you want but using the environment’s name might be wise).
(new-env)$ipython kernel install --user --name=new-env
  1. Now new-env will be displayed in your list of kernels (no need to restart Jupyter Notebook — just reload the page in your browser).

  2. When you want to un-register that kernel spec (remove the environment’s kernel from the list of available kernels) use the following command:

$jupyter kernelspec uninstall new-env

Pydantic

- conda install -y -c conda-forge pydantic 
- pip install datamodel-code-generator
conda install -c anytree
conda install -c treelib
conda install pydantic

Dash

  • conda install --name=og22dash3 -y -c conda-forge
  • dash pandas numpy matplotlib Werkzeug
  • dash-bootstrap-components
  • conda install -y -c conda-forge dash==2.1
⚠️ **GitHub.com Fallback** ⚠️