python自定义安装选项_python setup.py配置在自定义目录中安装文件

1586010002-jmsa.png

I want to create a setup.py which would install my files into custom directories. I have a certain prefix, where I would like to get the following result:

/my/prefix/

bin/

script.sh

libexec/

one.py

two.py

...

lib/pythonX.Y/site-packages/

package/...

My initial project is following:

/

script.sh

one.py

two.py

...

setup.py

package/...

__init__.py

...

What would be the best way to achieve that? I would like to be able to install it later with something like:

python setup.py install --prefix=/my/prefix

I can get "package" nicely installed in the correct directory as lib/pythonX.Y/site-packages under --prefix is the default location. But is there a clean way to get script.sh into "bin" and other python files into "libexec"? The only way I see to achieve that would be to manually copy those files in my setup.py script. May-be there is a cleaner and more standard way to do that?

(edit)

Solution

I ended up with setup.py like that:

setup(name='mylib',

scripts=['script.sh'],

data_files=[('libexec', ['one.py', 'two.py'])]

)

Of course, you could iterate over all python files for libexec, but I only have 2-3 python files I need there.

(edit2)

Additionally, I can have setup.cfg with the following:

[install]

prefix=/my/prefix

and instead of python setup.py install --prefix=/my/prefix I can just do:

python setup.py install

解决方案

The scripts are handled by use of the scripts parameter to the setup function. For libexec you can treat them as data files and use a data options.

setup(...

scripts=glob("bin/*"),

data_files=[(os.path.join(sys.prefix, 'libexec', 'mypackage'), glob("libexec/*"))],

...

)

I'm not sure how that would work with a --prefix option, I've never tried that.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值