如何避免文件未找到错误使用pip安装tarball?

时间:2014-05-16 20:39:01

标签: python pip setuptools

我正在构建一个本地python包

cd <source dir>
python ./setup.py sdist

当我尝试使用pip安装它时,它会尝试删除不存在的文件,然后失败。

pip install --verbose dist/pl_zenoss_handler-0.1.1.tar.gz
Unpacking ./dist/pl_zenoss_handler-0.1.1.tar.gz
  Running setup.py (path:/tmp/pip-QohNov-build/setup.py) egg_info for package from file:///Users/travis.bear/p4/depot/service/python/_pl_zenoss_handler/dist/pl_zenoss_handler-0.1.1.tar.gz
    running egg_info
    creating pip-egg-info/pl_zenoss_handler.egg-info
    writing pip-egg-info/pl_zenoss_handler.egg-info/PKG-INFO
    writing top-level names to pip-egg-info/pl_zenoss_handler.egg-info/top_level.txt

<... much output deleted for brevity ... >

creating build/scripts-2.7

error: file '/private/tmp/pip-QohNov-build/bin/zen_handler' does not exist

----------------------------------------
Cleaning up...
Command /Users/travis.bear/venv/zenoss/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-QohNov-build/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-uIoyIG-record/install-record.txt --single-version-externally-managed --compile --install-headers /Users/travis.bear/venv/zenoss/include/site/python2.7 failed with error code 1 in /tmp/pip-QohNov-build
Exception information:
Traceback (most recent call last):
  File "/Users/travis.bear/venv/zenoss/lib/python2.7/site-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/Users/travis.bear/venv/zenoss/lib/python2.7/site-packages/pip/commands/install.py", line 279, in run
    requirement_set.install(install_options, global_options, root=options.root_path)
  File "/Users/travis.bear/venv/zenoss/lib/python2.7/site-packages/pip/req.py", line 1380, in install
    requirement.install(install_options, global_options, *args, **kwargs)
  File "/Users/travis.bear/venv/zenoss/lib/python2.7/site-packages/pip/req.py", line 699, in install
    cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False)
  File "/Users/travis.bear/venv/zenoss/lib/python2.7/site-packages/pip/util.py", line 697, in call_subprocess
    % (command_desc, proc.returncode, cwd))
InstallationError: Command /Users/travis.bear/venv/zenoss/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-QohNov-build/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-uIoyIG-record/install-record.txt --single-version-externally-managed --compile --install-headers /Users/travis.bear/venv/zenoss/include/site/python2.7 failed with error code 1 in /tmp/pip-QohNov-build

Storing debug log for failure in /Users/travis.bear/.pip/pip.log

这是setup.py文件:

from setuptools import setup

readme = open('README.rst').read()
history = open('HISTORY.rst').read().replace('.. :changelog:', '')

setup(
    name='pl_zenoss_handler',
    version='0.1.1',
    description='Sensu handler for Zenoss',
    long_description=readme + '\n\n' + history,
    author='Travis Bear',
    author_email='<snip>',
    url='<snip>',
    packages=[
        'zen_handler',
    ],
    scripts=['bin/zen_handler'],
    install_requires=[
    ],
    license="BSD",
    keywords='zenoss sensu'
)

1 个答案:

答案 0 :(得分:1)

问题:分发包中缺少bin/zen_handler个文件

问题是,您的setup.py要求使用bin/zen_handler中的文件以及您的分发gz文件中缺少该文件。

怎么回事?

  1. 您的源代码树中有bin/zen_handler
  2. 您的setup.py定义了创建分发包的条件
  3. 您创建分发广告
  4. 您使用分发包来安装程序
  5. 分发包不包含bin/zen_handler并失败。
  6. 如果gz文件包含bin/zen_handler,您应该检查。我会假设,它不存在。

    原因是,因为它不是python包zen_handler本身的一部分,所以它不会打包成分发。

    分辨率

    将此非python文件声明为分发

    的一部分

    找到setup.py的选项,它甚至会将bin/zen_handler声明为分发包的一部分。这可能意味着编辑MANIFEST.in文件(在那里添加该文件)和/或使用参数include_package_data

    (首选)使用entry_points

    安装脚本

    不使用paremater scripts,而是使用Automatic Script Creation中所述的entry_point。由于这是使用纯包python源代码,因此不需要在外部存在文件。

    我建议使用此解决方案,即使代码中几乎不需要修改。