上传和安装标准Python包#
要使用标准的Python包,您必须使用相应的子域https://pypi.anaconda.org
。例如,要从用户travis
安装标准的Python包,请使用仓库URLhttps://pypi.anaconda.org/travis
。
上传标准Python包#
我们可以使用保存在anaconda-client 仓库中的一个小型公共示例包来测试标准的 Python 包上传。
使用 Anaconda Prompt(在 macOS/Linux 上为 Terminal)执行以下步骤:
首先从命令行克隆仓库:
# 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/
上获取,其中/
是您的用户名,
是包名称。
安装标准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 提示符(在 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客户端上传一个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