【问题标题】:Activate anaconda environment during vagrant shell provisioning在 vagrant shell 配置期间激活 anaconda 环境
【发布时间】:2017-03-08 23:30:28
【问题描述】:

我正在使用 vagrant(MacOSX Sierra 上的 1.9.1)在 VirtualBox 上配置 ubuntu/xenial64 框以运行 python 应用程序。我无法在配置时使用普通的 shell 命令source 激活 conda 环境。在我的bootstrap.sh 中,我有以下几行来创建一个新环境,然后切换到它。

#!/usr/bin/env bash
set -e # Exit script immediately on first error.
set -x # Print commands and their arguments as they are executed.

/home/ubuntu/miniconda3/bin/conda create --name envmycondaenvironment python=3.5 # environment with python3.5
source activate envgatherurls

我从 vagrant 收到以下错误。

==> default: + source activate envmycondaenvironment
==> default: /tmp/vagrant-shell: line 21: activate: No such file or directory

为什么shell脚本找不到activate?我验证了/home/ubuntu/miniconda3/bin/ 可以找到activate 的位置已添加到.bashrc 文件的PATH 中。

【问题讨论】:

    标签: shell vagrant vagrantfile vagrant-provision miniconda


    【解决方案1】:

    activate 命令由conda 提供,不会自动添加到PATH 环境变量中。请注意bootstrap.sh 脚本以root 而不是vagrant 用户身份运行。因此,您需要确保root 用户的.bashrc 在其路径中有/home/ubuntu/miniconda3/bin。如果我是你,我宁愿这样做:

    #!/usr/bin/env bash
    set -e # Exit script immediately on first error.
    set -x # Print commands and their arguments as they are executed.
    
    export PATH=/home/ubuntu/miniconda3/bin:$PATH
    conda create --name envmycondaenvironment python=3.5 # environment with python3.5
    source activate envgatherurls
    

    【讨论】:

      猜你喜欢
      • 2016-11-28
      • 2017-09-07
      • 2019-10-23
      • 2020-03-14
      • 2013-12-03
      • 2021-09-06
      相关资源
      最近更新 更多