在 python相关技巧 一文,已经介绍了普通用户如何安装软件,如何搭建私有的pip服务器等知识点;
这里对pip相关的内容进行整理总结
切换软件源
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U |
创建pypi项目
在进行dlib的学习时,发现dlib必须进行编译安装; 在使用docker时,(因为需要安装编译环境)会显著增大docker镜像的“体积”。因此,想到一个问题:是否可以在pypi上创建一个包,使得在进行安装时直接安装编译好的dlib,而不用编译?
按照官网文档 Packaging Python Projects操作即可。 具体到dlib,因官网已经提供了完善了编译打包脚本,在合适的环境编译后,上传到pypi上就可以了
例如,创建dlib-binary包,
根据官网的教程准备项目代码
fork dlib, 修改 setup.py
setup( |
安装 setuptools wheel
python3 -m pip install --upgrade setuptools wheel
编译打包
python3 setup.py sdist bdist_wheel
其中 sdist
指源代码包; bdist_wheel
指生成whl包
安装twine
python3 -m pip install --upgrade twine
上传到pypi
twine upload dist/*
TroubleShooting
报错:
HTTPError: 400 Bad Request from https://upload.pypi.org/legacy/ |
修改文件名为 dlib_binary-19.21.99-cp36-cp36m-manylinux1_x86_64.whl
后重新上传