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
- 下一篇: 如何安装微x(vx)模块如何使用太极软件