上传和安装 conda 包#

要使用 conda 包,您必须使用相应的子域名 https://conda.anaconda.org。 例如,要从用户 travis 安装 conda 包,请使用存储库 URL https://conda.anaconda.org/travis

上传 conda 包#

此示例演示如何使用 conda build 构建 conda 包并将其上传到 Anaconda.org。

  1. 打开 Anaconda Prompt(macOS/Linux 上的终端)。

  2. 如有必要,通过运行以下命令安装 anaconda-clientconda-build

    conda install anaconda-client conda-build
    
  3. 选择您要为其构建包的存储库。 在此示例中,我们使用一个小的公共 conda 测试包

    # Replace <PACKAGE> with the package name
    git clone https://github.com/Anaconda-Platform/anaconda-client
    cd anaconda-client/<PACKAGE>/conda/
    

    在此目录中,有两个必需的文件,meta.yamlbuild.sh

    macOS 和 Linux 系统是 Unix 系统。 为 Unix 系统构建的包需要 build.sh 文件,为 Windows 构建的包需要 bld.bat 文件,为 Windows 和 Unix 系统构建的包需要 build.sh 文件和 bld.bat 文件。 所有包都需要 meta.yaml 文件。

  4. 要构建包,请关闭自动客户端上传,然后运行 conda build 命令

    conda config --set anaconda_upload no
    conda build .
    

    以这种方式构建的所有包都放置在 Anaconda conda-bld 目录的子目录中。

    提示

    您可以通过添加 --output 选项来检查结果文件放置的位置

    conda build . --output
    
  5. 通过运行 anaconda upload 命令将测试包上传到 Anaconda.org

    anaconda login
    
    # Replace </PATH/TO/PACKAGE_NAME> with the correct file path and package name
    # Packages can be uploaded with .tar.bz2 or .conda compression formats
    anaconda upload </PATH/TO/PACKAGE_NAME>.tar.bz2
    anaconda upload </PATH/TO/PACKAGE_NAME>.conda
    

有关 .conda 格式的更多信息,请参阅 使用 .conda 压缩格式

有关 conda 整体构建框架的更多信息,请查看我们关于 构建 conda 包 的文章。

安装 conda 包#

您可以通过将频道添加到您的 conda 配置来从 Anaconda.org 安装 conda 包。

公共频道#

  1. 打开 Anaconda Prompt(macOS/Linux 上的终端)。

  2. 由于 conda 知道如何与 Anaconda.org 交互,因此指定频道 sean 例如,会转换为 https://anaconda.org/sean

    conda config --add channels sean
    
  3. 您现在可以从 Sean 的 Anaconda.org 帐户安装公共 conda 包。 尝试安装 testci 包,网址为 https://anaconda.org/sean/testci

    conda install testci
    

私有频道#

您可以使用令牌和 标签 从私有频道安装包

# Replace <TOKEN> with the provided token
# Replace <CHANNEL> with a user channel
# Replace <LABEL_NAME> with the label name
# Replace <PACKAGE> with the name of the package you want to install
conda install --channel https://conda.anaconda.org/t/<TOKEN>/<CHANNEL>/label/<LABEL_NAME> <PACKAGE>

仅当频道为私有频道时才需要令牌。

查找上传包的帮助#

您可以获得完整的上传选项列表,包括

  • 包频道。

  • 标签。

  • 对其他用户的可用性。

  • 元数据。

要列出选项,请在 Anaconda Prompt(macOS/Linux 上的终端)中运行以下命令

anaconda upload -h