Conda - Silently installing a package

PythonCondaInstallation PackageMiniconda

Python Problem Overview


I am trying to automate the process of setting up a development environment with pandas package using conda.

I installed conda, created and activated a dev environment. When I tried to install a package as follows, I noticed that there was a prompt to which a user had to key in Y or N (Proceed ([y]/n)?) for the installation to proceed successfully.

$ conda install pandas
Fetching package metadata: ....
Solving package specifications: ..................
Package plan for installation in environment /home/miniconda2/envs/pandas_env:

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    libgfortran-1.0            |                0         170 KB
    openblas-0.2.14            |                3         3.5 MB
    numpy-1.10.2               |           py27_0         5.9 MB
    pytz-2015.7                |           py27_0         174 KB
    six-1.10.0                 |           py27_0          16 KB
    python-dateutil-2.4.2      |           py27_0         219 KB
    pandas-0.17.1              |      np110py27_0        12.4 MB
    ------------------------------------------------------------
                                           Total:        22.3 MB

The following NEW packages will be INSTALLED:

    libgfortran:     1.0-0             
    numpy:           1.10.2-py27_0     
    openblas:        0.2.14-3          
    pandas:          0.17.1-np110py27_0
    python-dateutil: 2.4.2-py27_0      
    pytz:            2015.7-py27_0     
    six:             1.10.0-py27_0     

Proceed ([y]/n)? y

Fetching packages ...
libgfortran-1. 100% |###################################################################################################################################################################| Time: 0:00:00 457.23 kB/s
openblas-0.2.1 100% |###################################################################################################################################################################| Time: 0:00:02   1.68 MB/s
numpy-1.10.2-p 100% |###################################################################################################################################################################| Time: 0:00:02   2.42 MB/s
pytz-2015.7-py 100% |###################################################################################################################################################################| Time: 0:00:00 388.35 kB/s
six-1.10.0-py2 100% |###################################################################################################################################################################| Time: 0:00:00 224.69 kB/s
python-dateuti 100% |###################################################################################################################################################################| Time: 0:00:00 493.15 kB/s
pandas-0.17.1- 100% |###################################################################################################################################################################| Time: 0:00:04   3.24 MB/s
Extracting packages ...
[      COMPLETE      ]|######################################################################################################################################################################################| 100%
Linking packages ...
[      COMPLETE      ]|######################################################################################################################################################################################| 100%

How can I override these prompts so that the installation takes place silently? I tried using the -f flag but it does not seem to be existing with the conda install command.

Thanks in advance!

Python Solutions


Solution 1 - Python

Used $conda install -y pandas and it installed without any prompts (see documentation).

Solution 2 - Python

One-time Use

-y, --yes option.

# e.g. No.1
conda create -n myenv python=3.6 -y

# e.g. No.2
# install into a specific environment
conda install -n myenv requests -y
# install into the "base" env
conda install flake8 --yes

Script Use

Warning. This method confirms any type of prompt.

export CONDA_ALWAYS_YES="true"

# confirm all following "conda" commands
conda create -n myenv
conda install -n myenv requests
# ...

# Disable yes to all
unset CONDA_ALWAYS_YES 

You may need to check How to activate conda env through shell script.


Environment Specific Use

Warning. This method confirms any type of prompt.

Enable "yes" to any prompt within current active env.

# enable yes to all in current env
conda config --env --set always_yes true

# disable it in current env
conda config --env --remove always_yes

Solution 3 - Python

I suggest not to pass the confirmation process.

because it always has important info regarding this installation(which package will be updated and which dependency package will be installed and which package will be downgraded)

I once corrupt my environment due to not notice the update some of the package and took a long time to figure out some package need to stay in a older version to make some other package run properly.And that confirmation details will always makes you informed and tell you where to debug once you corrupt your package environment after installation

Anyway, here is the solution. Just use -y flag :

conda install -y PACKAGE_NAME

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionactivelearnerView Question on Stackoverflow
Solution 1 - PythonactivelearnerView Answer on Stackoverflow
Solution 2 - PythonSimbaView Answer on Stackoverflow
Solution 3 - PythoncloudscomputesView Answer on Stackoverflow