上传和安装标准 Python 包#

要使用标准 Python 包,您必须使用相应的子域名 https://pypi.anaconda.org。例如,要从用户 travis 安装标准 Python 包,请使用仓库 URL https://pypi.anaconda.org/travis

上传标准 Python 包#

我们可以使用保存在 anaconda-client 仓库 中的小型公共示例包来测试标准 Python 包上传。

使用 Anaconda Prompt(macOS/Linux 上的终端)执行以下步骤

  1. 首先从命令行克隆仓库

    # Replace <PACKAGE> with the package name
    git clone git@github.com:Anaconda-Platform/anaconda-client.git
    cd anaconda-client/<PACKAGE>/pypi/
    
  2. 您现在可以使用 setup.py 脚本创建您的标准 Python 包

    python setup.py sdist
    
  3. 该包现已构建为源 tarball,可以上传了

    anaconda upload dist/*.tar.gz
    

    您的包现在可以在 http://anaconda.org/<USERNAME>/<PACKAGE> 上找到,其中 <USERNAME> 是您的用户名,<PACKAGE> 是包名称。

安装标准 Python 包#

安装标准 Python 包的最佳方法是使用 pip。对于以下命令,我们使用在上面的示例中编写的包。打开 Anaconda Prompt(macOS/Linux 上的终端)并运行以下命令

# Replace <USERNAME> with your username
pip install --extra-index-url https://pypi.anaconda.org/<USERNAME>/simple pypi-test-package

安装私有标准 Python 包#

管理访问权限或使标准 Python 包和其他包私有的最佳方法是创建组织群组,它们允许您为每个包设置单独的权限。

您还可以使用令牌系统控制访问权限。所有 Anaconda.org URL 都可以附加 /t/$TOKEN 以访问私有包。

打开 Anaconda Prompt(macOS/Linux 上的终端)并运行以下命令

# Replace <TOKEN_NAME> with the name of the token you created
# Replace <USERNAME> with your username
# Replace <SIMPLE_TEST_PACKAGE> with the actual test-package name
TOKEN=$(anaconda auth --create --name <TOKEN_NAME>)
pip install --index-url https://pypi.anaconda.org/t/$TOKEN/<USERNAME>/<SIMPLE_TEST_PACKAGE>

使用标准 Python Wheel 文件#

当 Anaconda Client 上传 wheel 文件时,它使用标准的 Python 兼容包名称格式。这会将任何下划线 (_) 和句点 (.) 替换为破折号 (-)。如果您需要将 wheel 文件添加到已存在的 conda 包,并且该包名称包含下划线或句点,请使用 --package-p 标志指定包名称。

# Replace <PACKAGE> with the package name
# Replace </PATH/TO/WHEEL_FILE> with the wheel file and the file path
anaconda upload --package <PACKAGE> </PATH/TO/WHEEL_FILE>

查找上传包的帮助#

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

  • 包频道。

  • 标签。

  • 对其他用户的可用性。

  • 元数据。

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

anaconda upload -h