欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > python >内容正文

python

Python搭建私有pypi源发包——pypi-server

发布时间:2023/12/29 python 33 豆豆
生活随笔 收集整理的这篇文章主要介绍了 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 twine

htpasswd 在线生成器

创建密码文件

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_wheel




4. 上传包到私有 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-server GitHub
  • setuptools Documentation
  • twine Documentation
  • 基于 pypiserver 的 PyPI 私有仓库搭建实践
  • 如何搭建自己的pypi私有源服务器
  • pypi发包教程
  • Python打包工具setuptools的使用
  • python分发包管理
  • Python编程:twine模块打包python项目上传pypi
  • Python编程:为世界贡献你的轮子-pipy打包
  • 使用pypi-server搭建简单的PyPI源
  • htpasswd - 管理用于basic认证的用户文件
  • Powershell - 创建文本文件
  • 总结

    以上是生活随笔为你收集整理的Python搭建私有pypi源发包——pypi-server的全部内容,希望文章能够帮你解决所遇到的问题。

    如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。