繁体   English   中英

如何避免使用pip安装tarball时出现“找不到文件”错误?

[英]How do I avoid a file not found error installing a tarball with pip?

我正在构建一个本地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'
)

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

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

怎么样了

  1. 您的源代码树中有bin/zen_handler
  2. 您的setup.py定义了创建分发包的条件
  3. 您创建分发plackage
  4. 您使用分发包来安装程序
  5. 分发程序包不包含bin/zen_handler并失败。

您应该检查gz文件是否包含bin/zen_handler 我会假设它不存在。

原因是,由于它不是python包zen_handler本身的一部分,因此未打包到发行版中。

解析度

声明此非python文件作为分发的一部分

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

(首选)使用entry_points安装脚本

代替使用Paremater scripts ,而是使用“ 自动脚本创建”中所述的entry_point 由于这是使用纯软件包python源代码,因此不需要外部文件。

我推荐此解决方案,即使您只需对代码进行少许修改即可。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM