上传和安装标准 Python 包#
要使用标准 Python 包,您必须使用相应的子域 https://pypi.anaconda.org
。例如,要从用户 travis
安装标准 Python 包,请使用存储库 URL https://pypi.anaconda.org/travis
。
上传标准 Python 包#
我们可以使用保存在 anaconda-client 存储库 中的一个小型公共示例包来测试标准 Python 包上传。
使用终端(Windows 用户的 Anaconda Prompt)执行以下步骤
首先从命令行克隆存储库
# Replace <PACKAGE> with the package name git clone git@github.com:Anaconda-Platform/anaconda-client.git cd anaconda-client/<PACKAGE>/pypi/
您现在可以使用
setup.py
脚本创建标准 Python 包python setup.py sdist
该包现在已作为源代码压缩包构建,并已准备好上传
anaconda upload dist/*.tar.gz
您的包现在可以在
http://anaconda.org/<USERNAME>/<PACKAGE>
中使用,其中<USERNAME>
是您的用户名,而<PACKAGE>
是包名。
安装标准 Python 包#
安装标准 Python 包的最佳方法是使用 pip
。对于以下命令,我们使用我们在上述示例中创作的包。打开终端(Windows 用户的 Anaconda Prompt)并运行以下命令
# 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
以访问私有包。
打开终端(Windows 用户的 Anaconda Prompt)并运行以下命令
# 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>
查找上传包的帮助#
您可以获得上传选项的完整列表,包括
包频道。
标签。
对其他用户的可用性。
元数据。
要列出选项,请在终端(Windows 用户的 Anaconda Prompt)中运行以下命令
anaconda upload -h