Python version management tool – conda

Adding a python package

The default installation path should be site-packages of python folder. However, if you’d like to add a python package with customized installation path to the conda env: use command conda-develop.

Adding shared libraries

Check here for conda shared libraries.

Conda depends primarily on searching directories for matching filenames. It does not currently use side-by-side assemblies.

For now, most DLLs are installed into (install prefix)\\Library\\bin –Q:what is this path?. This path is added to os.environ["PATH"] for all Python processes, so that DLLs can be located, regardless of the value of the system’s PATH environment variable.

Check the list of the installed packages:

conda list

# or show only pip packages
pip list
Execution environment var setting in conda env

Reference here.

cd $CONDA_PREFIX

# edit the var 
vim etc/conda/activate.d/env_vars.sh
# example content: export MY_KEY='secret-key-value'
vim etc/conda/deactivate.d/env_vars.sh
# example content: unset MY_KEY

# Check by the following
conda activate analytics

Another option to add a Python packages folder to conda path: (Not verified yet)

To permanently include packages or folder into the PYTHONPATH of an conda environment, use conda develop:

conda activate <your-env>

conda develop /PATH/TO/YOUR/FOLDER/OF/MODULES

This command will create file named conda.pth file in the site-packages folder of your environment, e.g. ~/YOUR_ENV/lib/pythonX.X/site-packages.

As an alternative, you can just add a conda.pth file in ~/YOUR_ENV/lib/pythonX.X/site-packages with the folder that you want to include in your PYTHONPATH. The filename can be different as long as it has the .pth extension. Every line of the file can contain a folder.

Using the .condarc conda configuration file

The .condarc file can change many parameters, including:

  • Where conda looks for packages.
  • If and how conda uses a proxy server.
  • Where conda lists known environments.
  • Whether to update the Bash prompt with the currently activated environment name.
  • Whether user-built packages should be uploaded to Anaconda.org.
  • What default packages or features to include in new environments.

Creating and editing the .condarc with conda config commads. Example:

conda config --add channels conda-forge
conda config --set auto_update_conda False

Conda looks in the following locations for a .condarc file:

if on_win:
    SEARCH_PATH = (
        "C:/ProgramData/conda/.condarc",
        "C:/ProgramData/conda/condarc",
        "C:/ProgramData/conda/condarc.d",
    )
else:
    SEARCH_PATH = (
        "/etc/conda/.condarc",
        "/etc/conda/condarc",
        "/etc/conda/condarc.d/",
        "/var/lib/conda/.condarc",
        "/var/lib/conda/condarc",
        "/var/lib/conda/condarc.d/",
    )

SEARCH_PATH += (
    "$CONDA_ROOT/.condarc",
    "$CONDA_ROOT/condarc",
    "$CONDA_ROOT/condarc.d/",
    "$XDG_CONFIG_HOME/conda/.condarc",
    "$XDG_CONFIG_HOME/conda/condarc",
    "$XDG_CONFIG_HOME/conda/condarc.d/",
    "~/.config/conda/.condarc",
    "~/.config/conda/condarc",
    "~/.config/conda/condarc.d/",
    "~/.conda/.condarc",
    "~/.conda/condarc",
    "~/.conda/condarc.d/",
    "~/.condarc",
    "$CONDA_PREFIX/.condarc",
    "$CONDA_PREFIX/condarc",
    "$CONDA_PREFIX/condarc.d/",
    "$CONDARC",
)
Conda env creation using a yml file

TODO

Update conda environment:

conda env export > environment.yml
# Tip: backup your env before update
# --prune option removes any packages from the environment that are not listed in the .yml.
conda env update --file environment.yml --prune

References