setup.py:只安装一个pth文件?

时间:2010-01-27 09:43:18

标签: python

作为构建自定义python的最后一步,我需要添加myproject.pth

目前我在Makefile中执行此操作:

install:
        rm -f            ../../lib/python2.6/site-packages/myproject.pth
        cp myproject.pth ../../lib/python2.6/site-packages/myproject.pth

但我想将其封装在setup.py中。不幸的是,setup.py文档似乎并没有涵盖这个简单的案例!任何帮助赞赏。我尝试了这个,但它不起作用:

from setuptools import setup
setup(
    packages=['mypackage_pth'],
    package_dir={'mypackage_pth': '.'},
    package_data={'mypackage_pth': ['mypackage.pth']},
)

2 个答案:

答案 0 :(得分:5)

您正在寻找要设置的data_files参数:

from distutils import sysconfig
site_packages_path = sysconfig.get_python_lib()

setup(...,
  data_files=[(site_packages_path, ["mypackage.pth"])]
 )

答案 1 :(得分:1)

改编自stderr的回答。不确定你是否假设这样做,但它确实有用。

from distutils import sysconfig
site_packages_path = sysconfig.get_python_lib()

import shutil
shutil.copy('mypackage.pth', site_packages_path)

setup(...)