Python-将脚本安装到系统 [英] Python - install script to system
问题描述
如何为自己的脚本制作setup.py文件?我必须将脚本全局化. (将其添加到/usr/bin),因此我可以从控制台运行它,只需键入:scriptName参数. 操作系统:Linux. 编辑: 现在我的脚本可以安装了,但是如何使其全局化?这样我就可以从控制台运行它,而只需输入名称.
how can I make setup.py file for my own script? I have to make my script global. (add it to /usr/bin) so I could run it from console just type: scriptName arguments. OS: Linux. Now my script is installable, but how can i make it global? So that i could run it from console just name typing.
推荐答案
此答案仅涉及将可执行脚本安装到/usr/bin
中.我假设您具有setup.py
文件如何工作的基本知识.
This answer deals only with installing executable scripts into /usr/bin
. I assume you have basic knowledge on how setup.py
files work.
创建脚本并将其放置在项目中,如下所示:
Create your script and place it in your project like this:
yourprojectdir/
setup.py
scripts/
myscript.sh
在您的setup.py
文件中执行以下操作:
In your setup.py
file do this:
from setuptools import setup
# you may need setuptools instead of distutils
setup(
# basic stuff here
scripts = [
'scripts/myscript.sh'
]
)
然后输入
python setup.py install
基本上就是这样.您的脚本有可能不完全落在/usr/bin
中,而是落在其他目录中.在这种情况下,键入
Basically that's it. There's a chance that your script will land not exactly in /usr/bin
, but in some other directory. If this is the case, type
python setup.py install --help
并搜索--install-scripts
参数和朋友.
这篇关于Python-将脚本安装到系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!