setup.py - 安装后将模块符号链接到/usr/bin [英] setup.py - Symlink a module to /usr/bin after installation
问题描述
我几乎已经完成了一个 python 包的开发,并且还使用 distutils 编写了一个基本的 setup.py:
I've almost finished developing a python package and have also written a basic setup.py using distutils:
#!/usr/bin/env python
#@author: Prahlad Yeri
#@description: Small daemon to create a wifi hotspot on linux
#@license: MIT
import cli
#INSTALL IT
from distutils.core import setup
setup(name='hotspotd',
version='0.1',
description='Small daemon to create a wifi hotspot on linux',
license='MIT',
author='Prahlad Yeri',
author_email='prahladyeri@yahoo.com',
url='https://github.com/prahladyeri/hotspotd',
package_dir={'hotspotd': ''},
packages=['hotspotd'],
data_files=[('config',['run.dat'])],
)
#CONFIGURE IT
现在这个脚本可以按照我的意愿完美运行.它将所需的文件安装到前缀文件夹中.例如,下面的命令:
Now this script works perfectly as I want. It installs the required files to the prefixed folder. For example, the below command:
sudo python setup.py install --prefix /opt
将安装我的整个包:
/opt/lib/python2.7/site-packages/hotspotd
但是,我希望主要的可执行文件 hotspotd.py 被符号链接到/usr/bin 中的适当文件,例如:
However, I want the major executable, hotspotd.py to be symlinked to an appropriate file in /usr/bin such as:
/usr/bin/hotspotd
这样用户就可以通过简单地调用hotspotd start
而不是通过python间接调用来启动我的程序.
So that the user can start my program by simply calling hotspotd start
instead of indirectly invoking through python.
如何通过修改 setup.py 来实现这一点?如果我在 setup() 调用后在最后编写复制代码,则每次都会调用它.我只想在安装程序时完成.
How can I achieve this by modifying the setup.py? If I just write the copying code at the end after the setup() call, it would be called each time. I just want it done when the program is being installed.
推荐答案
只需像这样使用 scripts
参数:
Just use the scripts
parameter like this:
#!/usr/bin/env python
#@author: Prahlad Yeri
#@description: Small daemon to create a wifi hotspot on linux
#@license: MIT
import cli
#INSTALL IT
from distutils.core import setup
setup(name='hotspotd',
version='0.1',
description='Small daemon to create a wifi hotspot on linux',
license='MIT',
author='Prahlad Yeri',
author_email='prahladyeri@yahoo.com',
url='https://github.com/prahladyeri/hotspotd',
package_dir={'hotspotd': ''},
packages=['hotspotd'],
data_files=[('config',['run.dat'])],
scripts=["scriptname"], # Here the Magic Happens
)
#CONFIGURE IT
现在文件scriptname
将被复制到/usr/bin/scriptname
,shebang将被调用setup.py
的python版本替换代码> 脚本.所以明智地编写你的脚本.
Now the file scriptname
will be copied to /usr/bin/scriptname
the shebang will be replaced by the python version calling the setup.py
Script. So write your script wisely.
这篇关于setup.py - 安装后将模块符号链接到/usr/bin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!