python setup.py配置在自定义目录中安装文件 [英] python setup.py configuration to install files in custom directories

查看:3342
本文介绍了python setup.py配置在自定义目录中安装文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个setup.py,它会将我的文件安装到自定义目录中。我有一个特定的前缀,我想得到以下结果:

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/...

我的初始项目如下:

/
  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



我可以得到package正确安装在正确的目录lib / pythonX.Y / site -packages在--prefix下是默认位置。但是有一个干净的方式来获取script.sh到bin和其他python文件到libexec?我唯一的方法,我想实现这将是手动复制这些文件在我的setup.py脚本。

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?

(编辑)

解决方案

我最终使用了setup.py:

I ended up with setup.py like that:

setup(name='mylib',
  scripts=['script.sh'],
  data_files=[('libexec', ['one.py', 'two.py'])]
)



当然,你可以遍历所有python文件libexec ,但我只有2-3个python文件,我需要那里。

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

(edit2)

可以有以下setup.cfg:

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

[install]
prefix=/my/prefix

而不是 python setup.py install --prefix = / my / prefix 我可以这样做:

python setup.py install


推荐答案

脚本使用 scripts 参数到设置功能。对于libexec,您可以将它们视为数据文件并使用数据选项。

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.

这篇关于python setup.py配置在自定义目录中安装文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆