Python私有pypi源注册自定义依赖包Windows详解
作者:Junx_fu
一、pypi 源
1. 进入C盘,用户目录下,创建.pypirc文件(若报错没有文件名,则命名时为 .pypirc. ,保存后即为.pypirc)
2. 配置私有源,上传库及用户名密码,可配置多个
[distutils] index-servers = nexus, pypi [nexus] repository: username: password: [pypi] username: password:
二、开发包
2.1开发包结构
2.1.1 创建一个项目,项目名称需要为所上传依赖库中没有的名字
2.1.2 文件夹中未具体实现代码
2.1.3 __init__.py文件,from .文件名 import *,有几个文件from几次
2.1.4 LICENSE,可参考 Choose an open source licenseChoose an open source license | Choose a LicenseChoose 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 OTHERDEALINGS IN
THE SOFTWARE.
2.1.5 README.md 项目简介
2.1.6 setup.py
import setuptools setuptools.setup( # 项目的名称 name="", # 项目的版本 version="0.0.1", # 项目的作者 author="", # 作者的邮箱 author_email="", # 项目描述 description="", # 项目的长描述 long_description="", # 以哪种文本格式显示长描述 long_description_content_type="text/markdown", # 所需要的依赖 install_requires=[ 'pymongo' ], # 项目中包含的子包,find_packages() 是自动发现根目录中的所有的子包。 packages=setuptools.find_packages(), # 其他信息,这里写了使用 Python3,MIT License许可证,不依赖操作系统。 classifiers=[ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", ], )
三、生成包并上传
3.1生成 dist 目录
pip install wheel python setup.py sdist bdist_wheel
生成build、dist、xxx.egg.info
3.2上传
pip install twine twine upload dist/* -r nexus(nexus为配置文件中名称)
四、安装
4.1配置临时源
pip install jcdependency==0.0.1 -i 源 --trusted-host 信任 或 pip install jcdependency==0.0.1 -i 源
4.2配置永久源
进入进入C盘,用户目录下,创建pip文件夹,新增pip.ini
[global] timeout = 6000 index-url = 源 trusted-host = 信任 pip install jcdependency==0.0.1
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。