[英]rpm package from python source
I have a python script MyScript.py
. 我有一个Python脚本MyScript.py
。 I run it using python MyScript.py [options]
. 我使用python MyScript.py [options]
运行它。 But I want to make rpm package from it. 但是我想用它制作rpm包。 So I created setup.py
and created rpm package by using python setup.py bdist_rpm
. 因此,我使用python setup.py bdist_rpm
创建了setup.py
并创建了rpm包。 For this I changed file structure as below: 为此,我更改了文件结构,如下所示:
- MyScript
- __init__.py
- setup.py
setup.py: setup.py:
from distutils.core import setup
setup(name='MyScript',
version='0.0.1',
author='ABC XYZ',
author_email='abc@xyz.com',
packages=['MyScript']
)
When I run python setup.py bdist_rpm
, I get 2 rpm files ( noarch.rpm
, src.rpm
) and 1 tar.gz file under dist folder which is created automatically. 当我运行python setup.py bdist_rpm
,我在自动创建的dist文件夹下得到2个rpm文件( noarch.rpm
, src.rpm
)和1个tar.gz文件。 But When I use rpm -i
on norach.rpm
file, it just says that package is installed but I can not use the package when I try to run MyScript
command in bash. 但是,当我在norach.rpm
文件上使用rpm -i
时,它只是说该软件包已安装,但是当我尝试在bash中运行MyScript
命令时我无法使用该软件包。 Am I doing something wrong here? 我在这里做错什么了吗? Please guide me if so. 如果是这样,请指导我。 I am bit beginner to packaging. 我对包装有点初学者。
Yes, you are doing something wrong :) 是的,您做错了:)
The fact that you created an rpm and provided a MyScript
package does not mean that installing the rpm will expose an executable for you to run (ie $ MyScript ...
. To also making an executable available which will interact with the package, you need to provide an entry_point
in your setup.py file. 您创建了rpm并提供了MyScript
软件包的事实并不意味着安装rpm会公开一个可执行文件供您运行(即$ MyScript ...
要同时使可执行文件与软件包进行交互,您需要在setup.py文件中提供一个entry_point
。
An entry point pretty much maps a script which will be installed in the path to a function in your code and runs it. 入口点几乎映射了一个脚本,该脚本将安装在代码中某个函数的路径中并运行它。
Add something like this: 添加如下内容:
setup(name='MyScript',
version='0.0.1',
author='ABC XYZ',
author_email='abc@xyz.com',
packages=['MyScript'],
entry_point={
'console_scripts': [
'MyScript = MyScript.__init__:FUNC_NAME'
]
}
)
where FUNC_NAME
is the name of the function in the MyScript
package in the __init__
module to invoke. 其中, FUNC_NAME
是__init__
模块中要调用的MyScript
包中的函数的名称。
The general format (for future reference) of a console_script is: console_script的一般格式(供将来参考)是:
'name_of_executable = package.module:function_to_execute'
An example can be found here: https://chriswarrick.com/blog/2014/09/15/python-apps-the-right-way-entry_points-and-scripts/ 可以在此处找到示例: https : //chriswarrick.com/blog/2014/09/15/python-apps-the-right-way-entry_points-and-scripts/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.