我有一个简单的应用程序(只有一个 .py 文件),它使用 cherrypy 和 flask-restful 来提供 Web 服务。我的开发环境是Windows。我使用 Python 3.5.2 并创建和使用 virtualenv 来处理我的项目。
我需要在 Linux 系统上部署它。我被要求为此创建一个“RPM”,以便它可以在 Linux 机器上安装和运行。
我用谷歌搜索并阅读了几篇文档:
- https://docs.python.org/3.5/distutils/builtdist.html
- http://docs.python-guide.org/en/latest/shipping/packaging/
但我不太清楚在 Linux 系统上部署它需要完成的步骤。预先感谢您的所有帮助。
最佳答案
这是tree
命令输出的一个mini demo结构,color_print
是包名和目录
.
├── color_print
│ ├── color_print.py
│ └── __init__.py
├── __init__.py
└── setup.py
这里有一个示例 setup.py
用于演示
from setuptools import setup
setup(name='color_print',
version='0.1',
description='Color String',
url='http://github/xxxx/color_print/',
author='Joe Bob',
author_email='joe.bob@gmail.com',
license='MIT',
packages=['color_print'],
zip_safe=False)
无需更改目录,运行此命令即可构建 rpms
python setup.py bdist_rpm
这是输出,就是这么简单:
-bash-4.1$ find . -name "*.spec"
./build/bdist.linux-x86_64/rpm/SPECS/color_print.spec
-bash-4.1$ find . -name "*.rpm"
./dist/color_print-0.1-1.noarch.rpm
./dist/color_print-0.1-1.src.rpm
实际上,您肯定需要手动修改 spec 文件。并运行
rpmbuild -ba ./build/bdist.linux-x86_64/rpm/SPECS/color_print.spec
关于python - 如何为 python 应用程序创建 rpm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42286786/