Python 设置 PYPI 私服说明
私服设置
Linux 下编辑文件 /etc/pip.conf 或者 ~/.pip/pip.conf , Windows 下编辑文件 C:\ProgramData\pip\pip.ini 或者 %USERPROFILE%\pip\pip.ini 或者 %APPDATA%\pip\pip.ini, 添加 extra-index-url 修改 index-url
私服在找不到包时,会替我们到外面找包,因此只需要一个 index-url 即可
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| [global]
# 豆瓣源
# index-url = https://pypi.douban.com/simple
# 清华源
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
# 阿里云源
# index-url = https://mirrors.aliyun.com/pypi/simple
# 私服url
# extra-index-url = http://192.168.0.200:8080/simple
# 私服url
# index-url = http://192.168.0.200:8080/root/public
# trusted-host = 192.168.0.200
[search]
# index = http://192.168.0.200:8080/root/public
|
然后直接使用 pip install 即可。
由于 python 默认没有使用系统的证书,如果需要 python 使用系统的证书,则在 ~/.bashrc 中增加如下设置: (对于 windows 系统,还是先使用上面的 trusted-host 设置吧)
1
| export REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
|
某些情况下,由于 pip 已经缓存了一个不可用地址,导致即使私服里存在对应的包,也抛出找不到包的错误。这时可以尝试添加 --no-cache-dir 选项进行忽略已有缓存,完整命令为 pip install --no-cache-dir <pkg> 。
镜像上传方式介绍
编辑文件 ~/.pypirc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| [distutils]
index-servers =
# pypi
local
#注意上面必须有缩进
#[pypi]
#username:<your_pypi_username>
#password:<your_pypi_passwd>
[local]
# repository: http://192.168.0.200:8080
# 注意下面这个 url 后面必须带 /
repository: http://192.168.0.200:8080/root/public/
username: <some_username>
password: <some_passwd>
|
上传命令
1
2
3
4
5
6
7
8
9
10
11
12
| # python setup.py register -r local
# python setup.py sdist upload -r local
# 以上命令已废弃,推荐使用下列命令
# 打包
python3 setup.py sdist bdist_wheel
# 检查
twine check dist/*
# 上传
twine upload -r local dist/*
|