甜腻的嘴角|教你在几分钟内构建一个Python包( 二 )

太棒了! ! , 现在我们的包可以工作了 , 让我们继续进行下一个部分 。
上传Python包
甜腻的嘴角|教你在几分钟内构建一个Python包使用PyPI可以快速上传新构建的包 。 首先来看什么是PyPi 。 PyPi代表Python包索引(PyPi) , 它是Python编程语言的软件存储库 。
所以现在要将我们的包上载到PyPI站点的测试版本 , 另外要确保pip安装过程是否正常 , 然后现在要上载到PyPI站点 。
首先 , 用测试创建一个帐户 。 对两个站点使用相同的用户名和密码 。
在成功创建两个帐户之后 , 让我们返回IDE并将包上传到TestPyPi 。 但首先 , 要与这些站点通信 , 您需要pip安装一个名为twine的库 , 使用:
pip install twine所以 , 安装twine后 , 输入以下代码先上传到TestPyPi:
# Creating the distribution package to be uploaded~/python_package:$ python setup.py sdist输入代码后 , 您将看到两个新文件夹 , 然后移动到下一行代码:
# Upload the package created using twinw~/python_package:$ twine upload --repository-urldist/*Output: Uploading distributions to # enter your username and password used in registraion to the siteOutput: Enter your username : bideenOutput: Enter your password : ########输入密码后 , 你会看到一条成功的消息:“上传package_name 100%成功” 。 要检查上传是否成功 , 请访问您的TestPyPi帐户并查看您的新包 。
现在使用以下代码从TestPyPi站点安装pip:
# first uninstall the previuos package on to aviod conflicts~/python_package:$ pip uninstall b_dist# install fro the TestPyPi~/python_package:$ pip install --index-urlb_dist成功集成TestPyPi之后 , 现在让我们继续上载到主PyPi , 在那里可以使用包名直接进行pip安装 , 也可以公开使用 。
# first uninstall the previuos package on to aviod conflicts~/python_package:$ pip uninstall b_dist# install fro the TestPyPi~/python_package:$ pip install b_dist祝贺您 , 您已经成功地构建了一个python包 。 现在在pypi.org上检查新上传的包
英文原文:


推荐阅读