上传和安装标准 Python 包#
要使用标准 Python 包,您必须使用相应的子域https://pypi.anaconda.org
.从用户安装标准 Python 软件包travis
,例如,使用存储库 URLhttps://pypi.anaconda.org/travis
.
上传标准 Python 包#
我们可以使用保存在 anaconda-client 存储库中的小型公共示例包来测试标准 Python 包上传。
使用 Anaconda Prompt(macOS/Linux 上的终端)执行以下步骤:
首先从命令行克隆存储库:
# Replace <PACKAGE> with the package name git clone git@github.com:Anaconda-Platform/anaconda-client.git cd anaconda-client/<PACKAGE>/pypi/
现在,您可以使用
setup.py
脚本:python setup.py sdist
该包现在已经构建为源 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 包和其他包设为私有的最佳方法是创建组织或组,这允许您为每个包设置单独的权限。
您还可以使用Token系统控制访问。所有 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>
查找上传包的帮助#
您可以获取上传选项的完整列表,包括:
Package 频道。
标签。
对其他用户的可用性。
元数据。
要列出选项,请在 Anaconda Prompt(macOS/Linux 上的终端)中运行以下命令:
anaconda upload -h