二丫讲梵 二丫讲梵
首页
  • 最佳实践
  • 迎刃而解
  • Nginx
  • Php
  • Zabbix
  • AWS
  • Prometheus
  • Grafana
  • CentOS
  • Systemd
  • Docker
  • Rancher
  • Ansible
  • Ldap
  • Gitlab
  • GitHub
  • Etcd
  • Consul
  • RabbitMQ
  • Kafka
  • MySql
  • MongoDB
  • OpenVPN
  • KVM
  • VMware
  • Other
  • ELK
  • K8S
  • LLM
  • Nexus
  • Jenkins
  • 随写编年
  • 家人物语
  • 追忆青春
  • 父亲的朋友圈
  • 电影音乐
  • 效率工具
  • 博客相关
  • Shell
  • 前端实践
  • Vue学习笔记
  • Golang学习笔记
  • Golang编程技巧
  • 学习周刊
  • Obsidian插件周刊
关于
友链
  • 本站索引

    • 分类
    • 标签
    • 归档
  • 本站页面

    • 导航
    • 打赏
  • 我的工具

    • 备忘录清单 (opens new window)
    • json2go (opens new window)
    • gopher (opens new window)
    • 微信MD编辑 (opens new window)
    • 国内镜像 (opens new window)
    • 出口IP查询 (opens new window)
    • 代码高亮工具 (opens new window)
  • 外站页面

    • 开往 (opens new window)
    • ldapdoc (opens new window)
    • HowToStartOpenSource (opens new window)
    • vdoing-template (opens new window)
GitHub (opens new window)

二丫讲梵

行者常至,为者常成
首页
  • 最佳实践
  • 迎刃而解
  • Nginx
  • Php
  • Zabbix
  • AWS
  • Prometheus
  • Grafana
  • CentOS
  • Systemd
  • Docker
  • Rancher
  • Ansible
  • Ldap
  • Gitlab
  • GitHub
  • Etcd
  • Consul
  • RabbitMQ
  • Kafka
  • MySql
  • MongoDB
  • OpenVPN
  • KVM
  • VMware
  • Other
  • ELK
  • K8S
  • LLM
  • Nexus
  • Jenkins
  • 随写编年
  • 家人物语
  • 追忆青春
  • 父亲的朋友圈
  • 电影音乐
  • 效率工具
  • 博客相关
  • Shell
  • 前端实践
  • Vue学习笔记
  • Golang学习笔记
  • Golang编程技巧
  • 学习周刊
  • Obsidian插件周刊
关于
友链
  • 本站索引

    • 分类
    • 标签
    • 归档
  • 本站页面

    • 导航
    • 打赏
  • 我的工具

    • 备忘录清单 (opens new window)
    • json2go (opens new window)
    • gopher (opens new window)
    • 微信MD编辑 (opens new window)
    • 国内镜像 (opens new window)
    • 出口IP查询 (opens new window)
    • 代码高亮工具 (opens new window)
  • 外站页面

    • 开往 (opens new window)
    • ldapdoc (opens new window)
    • HowToStartOpenSource (opens new window)
    • vdoing-template (opens new window)
GitHub (opens new window)
  • Nexus系列文章

    • 前言
    • nexus的安装
    • 使用nexus3配置docker私有仓库
    • 使用nexus3配置maven私有仓库
    • 使用nexus3配置npm私有仓库
    • 使用nexus3配置yum私有仓库
    • 使用nexus3配置Python私有仓库
    • 使用nexus3配置golang私有仓库
    • maven私服nexus2-14-5迁移到nexus3-7-1
    • maven上传jar包以及SNAPSHOT的一个坑
    • Gradel上传本地包的一些坑及注意点
    • go1-12与1-14之私服使用的差异与变化
    • 通过命令行往python私仓传包
      • 1,前言
      • 2,上传
        • 1,先安装依赖包
        • 2,添加配置
        • 3,编写代码
        • 4,打包
        • 5,上传
      • 3,下载
    • 关于yum仓库往nexus私服传包等实践
    • 将maven本地包上传到nexus私服的实践
    • 将npm本地包上传到nexus私服的实践
    • nexus2.x升级到3.x之后仓库地址改变的问题探索
    • 关于gradle中plugins依赖未走私服导致编译失败的原因探析
  • Jenkins系列文章

  • ELK笔记

  • Kubernetes笔记

  • LLM专题

  • 系列专题
  • Nexus系列文章
二丫讲梵
2020-12-24
目录

通过命令行往python私仓传包

文章发布较早,内容可能过时,阅读注意甄别。

# 1,前言

提供了 Python 私仓之后,除了通过私仓拉包方便之外,小伙伴们难免会有往私仓传包的需求,因为稍微有点绕弯,因此这里记录一下。

其实用一句话来表述,就是通过私服拉包的时候,走group的代理,从本地上传包的时候,要走local的仓库。

接下来就记录一下配置方法并用测试包来验证下。

创建私服的过程这里不详述了,已知现有 Python 私仓,物料信息如下:

  • group:http://nexus.test.com/repository/pyg/
  • local:http://nexus.test.com/repository/pyg/

# 2,上传

# 1,先安装依赖包

$ pip3 install wheel --user
$ pip3 install twine --user
1
2

img

# 2,添加配置

有了如上物料之后,我们首先来验证下上传功能,在本地用户家目录添加如下配置:

$ cat ~/.pypirc
[distutils]
index-servers =
    pypi
    nexus
[pypi]
repository:https://pypi.python.org/pypi
username:eryajf
password:test
[nexus]
repository=http://nexus.test.com/repository/pyg/
username=dev
password=GVLaX-E|yq$vE[/k
1
2
3
4
5
6
7
8
9
10
11
12
13

申明

原创文章eryajf,未经授权,严禁转载,侵权必究!此乃文中随机水印,敬请读者谅解。

Copyright 二丫讲梵 (opens new window) 版权所有

# 3,编写代码

然后在本地打一个测试包

$ mkdir helloworld
$ touch helloworld/__init__.py
$ cat helloworld/demo.py
class Demo:
    @staticmethod
    def hello():
        print('helloworld')
1
2
3
4
5
6
7

编写 setup.py:

$ cat setup.py
from setuptools import setup
setup(
    name='helloworld',
    version='1.0',
    author="techlog",
    license="MIT",
    packages=[
        'helloworld'
    ],
    install_requires=[
    ],
    classifiers=[
        "Topic :: Utilities",
        "Topic :: Internet",
        "Topic :: Software Development :: Libraries :: Python Modules"
    ],
)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

具体的 setup.py 的编写规范可以参考:https://packaging.python.org/tutorials/distributing-packages/#setup-py

目录结构:

$ tree
.
├── helloworld
│   ├── __init__.py
│   └── demo.py
└── setup.py
1 directory, 3 files
1
2
3
4
5
6
7

# 4,打包

$ python3 setup.py sdist bdist_wheel
running sdist
running egg_info
creating helloworld.egg-info
writing helloworld.egg-info/PKG-INFO
writing dependency_links to helloworld.egg-info/dependency_links.txt
writing top-level names to helloworld.egg-info/top_level.txt
writing manifest file 'helloworld.egg-info/SOURCES.txt'
reading manifest file 'helloworld.egg-info/SOURCES.txt'
writing manifest file 'helloworld.egg-info/SOURCES.txt'
warning: sdist: standard file not found: should have one of README, README.rst, README.txt, README.md
running check
warning: check: missing required meta-data: url
warning: check: missing meta-data: if 'author' supplied, 'author_email' must be supplied too
creating helloworld-1.0
creating helloworld-1.0/helloworld
creating helloworld-1.0/helloworld.egg-info
copying files to helloworld-1.0...
copying setup.py -> helloworld-1.0
copying helloworld/__init__.py -> helloworld-1.0/helloworld
copying helloworld/demo.py -> helloworld-1.0/helloworld
copying helloworld.egg-info/PKG-INFO -> helloworld-1.0/helloworld.egg-info
copying helloworld.egg-info/SOURCES.txt -> helloworld-1.0/helloworld.egg-info
copying helloworld.egg-info/dependency_links.txt -> helloworld-1.0/helloworld.egg-info
copying helloworld.egg-info/top_level.txt -> helloworld-1.0/helloworld.egg-info
Writing helloworld-1.0/setup.cfg
creating dist
Creating tar archive
removing 'helloworld-1.0' (and everything under it)
running bdist_wheel
running build
running build_py
creating build
creating build/lib
creating build/lib/helloworld
copying helloworld/__init__.py -> build/lib/helloworld
copying helloworld/demo.py -> build/lib/helloworld
installing to build/bdist.macosx-10.14-x86_64/wheel
running install
running install_lib
creating build/bdist.macosx-10.14-x86_64
creating build/bdist.macosx-10.14-x86_64/wheel
creating build/bdist.macosx-10.14-x86_64/wheel/helloworld
copying build/lib/helloworld/__init__.py -> build/bdist.macosx-10.14-x86_64/wheel/helloworld
copying build/lib/helloworld/demo.py -> build/bdist.macosx-10.14-x86_64/wheel/helloworld
running install_egg_info
Copying helloworld.egg-info to build/bdist.macosx-10.14-x86_64/wheel/helloworld-1.0-py3.7.egg-info
running install_scripts
creating build/bdist.macosx-10.14-x86_64/wheel/helloworld-1.0.dist-info/WHEEL
creating 'dist/helloworld-1.0-py3-none-any.whl' and adding 'build/bdist.macosx-10.14-x86_64/wheel' to it
adding 'helloworld/__init__.py'
adding 'helloworld/demo.py'
adding 'helloworld-1.0.dist-info/METADATA'
adding 'helloworld-1.0.dist-info/WHEEL'
adding 'helloworld-1.0.dist-info/top_level.txt'
adding 'helloworld-1.0.dist-info/RECORD'
removing build/bdist.macosx-10.14-x86_64/wheel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

打包之后,会生成一个 build 目录和 dist 目录:

$ tree
.
├── build
│   ├── bdist.macosx-10.14-x86_64
│   └── lib
│       └── helloworld
│           ├── __init__.py
│           └── demo.py
├── dist
│   ├── helloworld-1.0-py3-none-any.whl
│   └── helloworld-1.0.tar.gz
├── helloworld
│   ├── __init__.py
│   └── demo.py
├── helloworld.egg-info
│   ├── PKG-INFO
│   ├── SOURCES.txt
│   ├── dependency_links.txt
│   └── top_level.txt
└── setup.py
7 directories, 11 files
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

# 5,上传

$ python3 -m twine upload --repository nexus dist/*
Uploading distributions to http://nexus.test.com/repository/pygl/
Uploading helloworld-1.0-py3-none-any.whl
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 4.38k/4.38k [00:00<00:00, 46.9kB/s]
Uploading helloworld-1.0.tar.gz
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3.77k/3.77k [00:00<00:00, 112kB/s]
1
2
3
4
5
6

看到如上内容,就说明上传成功了。

可以浏览器上看下:

image-20201120164214736

# 3,下载

拉包就比较简单了,首先配置如下信息:

mkdir ~/.pip
cat > ~/.pip/pip.conf << EOF
[global]
timeout = 60
trusted-host =  nexus.test.com
index-url = http://nexus.test.com/repository/pypi/simple
EOF
1
2
3
4
5
6
7

然后直接安装对应包即可。

微信 支付宝
#nexus#python
上次更新: 2024/07/04, 22:40:37
go1-12与1-14之私服使用的差异与变化
关于yum仓库往nexus私服传包等实践

← go1-12与1-14之私服使用的差异与变化 关于yum仓库往nexus私服传包等实践→

最近更新
01
记录二五年五一之短暂回归家庭
05-09
02
学习周刊-总第210期-2025年第19周
05-09
03
学习周刊-总第209期-2025年第18周
05-03
更多文章>
Theme by Vdoing | Copyright © 2017-2025 | 点击查看十年之约 | 浙ICP备18057030号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式