Python Conda - 静默安装软件包

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34644612/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 15:18:37  来源:igfitidea点击:

Conda - Silently installing a package

pythoncondainstallation-packageminiconda

提问by activelearner

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

我正在尝试使用 conda 自动化使用 pandas 包设置开发环境的过程。

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,创建并激活了一个开发环境。当我尝试按如下方式安装软件包时,我注意到有一个提示,用户必须键入 Y 或 N(Proceed ([y]/n)?)才能成功进行安装。

$ 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.

如何覆盖这些提示以便安装以静默方式进行?我尝试使用 -f 标志,但它似乎不存在于 conda install 命令中。

Thanks in advance!

提前致谢!

采纳答案by activelearner

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

使用$conda install -y pandas并在没有任何提示的情况下安装(请参阅文档)。

回答by cloudscomputes

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 -yflag :

无论如何,这是解决方案。只需使用-y标志:

conda install -y PACKAGE_NAME

回答by Simba

One-time Use

一次性使用

-y, --yesoption.

-y--yes选项。

# 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 anytype 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.

您可能需要检查如何通过 shell 脚本激活 conda env



Environment Specific Use

环境特定用途

Warning. This method confirms anytype of prompt.

警告。此方法确认任何类型的提示。

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

当前活动 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