Python搭建私有pypi源发包——pypi-server
生活随笔
收集整理的这篇文章主要介绍了
Python搭建私有pypi源发包——pypi-server
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
文章目录
- 简介
- 1. 搭建私有 pypi 源
- 2. 开发要上传的包
- 3. 生成 dist 目录用于上传
- 4. 上传包到私有 pypi 源
- 5. 安装
- Linux 安装
- 参考文献
简介
本地搭建 pypi 源,开发包,并在私有源上发包
以 Windows 为例,以管理员身份运行 PowerShell
1. 搭建私有 pypi 源
安装
pip install pypiserver mkdir ~/packages pip install passlib pip install setuptools pip install wheel pip install twinehtpasswd 在线生成器
创建密码文件
New-Item ~/.pypipasswd Set-Content ~/.pypipasswd '以上生成结果'启动
pypi-server -P C:\Users\Administrator\.pypipasswd访问 http://localhost:8080/
可用 Supervisor 启动守护进程,此处略
2. 开发要上传的包
新建项目 mytool
mytool.py
def show():print('Hello World!')__init__.py
from mytool import *LICENSE,可参考 Choose an open source license
The MIT License (MIT) Copyright (c) 2013 Steve Canny, https://github.com/scannyPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.README.md
# 简介我的工具setup.py,可参考 python-docx/setup.py
from setuptools import find_packages, setupsetup(name='mytool',version='0.0.1',description='我的工具',author='XerCis',author_email='',url='项目地址',license='MIT License',packages=find_packages(exclude=['build', 'dist', 'tests', 'tests.*']),include_package_data=True,install_requires=[],zip_safe=False, )3. 生成 dist 目录用于上传
python setup.py sdist bdist_wheel4. 上传包到私有 pypi 源
修改 pypirc 设置
cat ~/.pypirc如下
[distutils] index-servers =pypilocal[pypi] username: 在pypi上的用户名 password: 在pypi上的密码[local] repository: http://localhost:8080 username: 用户名 password: 密码上传到 local 仓库
twine upload dist/* -r local访问 http://localhost:8080/simple/
5. 安装
查找包
pip search -i http://localhost:8080 mytool安装包
pip install -i http://localhost:8080/simple mytool pip install -U -i http://localhost:8080/simple mytool安装最新包
pip install -U -i http://localhost:8080/simple mytool测试
from mytool import mytoolmytool.show()Linux 安装
创建密码那步可以这样:
安装工具包
sudo apt-get install -y apache2-utils创建用户名和密码
htpasswd -c ~/.pypipasswd XerCis查看
cat ~/.pypipasswd参考文献
总结
以上是生活随笔为你收集整理的Python搭建私有pypi源发包——pypi-server的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: Linux压缩pdf
- 下一篇: python java驾校报名考试信息管