繁体   English   中英

如何修复setuptools / wheel.py:157 _convert_metadata中的“无此文件或目录”错误

[英]How to fix “No such file or directory” error in setuptools/wheel.py:157 _convert_metadata

当运行python setup.py测试,python setup.py build甚至python setup.py --help-commands时,我得到一个“ OSError:[Errno 2] No such file or directory”。

到目前为止,我已经尝试升级setuptools(当前正在运行版本41.0.1),但这尚未解决问题。

我匿名的setup.py看起来像:

from setuptools import setup, find_packages


def read_version():
    with open('version') as ver:
        return ver.read().strip()


config = {
    'description': 'package',
    'author': 'Me',
    'author_email': 'email@email.com',
    'version': read_version(),
    'packages': find_packages(),
    'package_data': {
        'manager.resources': ['*.yaml'],
    },
    'scripts': [],
    'name': 'company.packagename',
    'namespace_packages': ['company'],
    'test_suite': 'tests',
    'entry_points': {
        'console_scripts': [
            'launcher = manager_launcher:main',
            'managerschemas = manager.validation:export',
            'managertypes = manager.types:export',
        ]
    },
    'setup_requires': ['pytest-runner'],
    'tests_require': [
        'flake8',
        'pylint',
        'pytest',
        'pytest-cov',
        'pytest-mock',
    ],
}

if __name__ == '__main__':
    setup(**config)

和setup.cfg是:

[aliases]
test = pytest

[flake8]
max-line-length = 120
exclude = venv,.eggs

[tool:pytest]
addopts = -vvvv --cov=manager --cov-branch --cov-fail-under=100 --cov-report=term --cov-report=html --junitxml=junit.xml
testpaths = tests

我得到的追溯是:

Traceback (most recent call last):
  File "setup.py", line 40, in <module>
    setup(**config)
  File "/home/vagrant/.local/lib/python2.7/site-packages/setuptools/__init__.py", line 144, in setup
    _install_setup_requires(attrs)
  File "/home/vagrant/.local/lib/python2.7/site-packages/setuptools/__init__.py", line 139, in _install_setup_requires
    dist.fetch_build_eggs(dist.setup_requires)
  File "/home/vagrant/.local/lib/python2.7/site-packages/setuptools/dist.py", line 717, in fetch_build_eggs
    replace_conflicting=True,
  File "/home/vagrant/.local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 782, in resolve
    replace_conflicting=replace_conflicting
  File "/home/vagrant/.local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1065, in best_match
    return self.obtain(req, installer)
  File "/home/vagrant/.local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1077, in obtain
    return installer(requirement)
  File "/home/vagrant/.local/lib/python2.7/site-packages/setuptools/dist.py", line 784, in fetch_build_egg
    return cmd.easy_install(req)
  File "/home/vagrant/.local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 679, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "/home/vagrant/.local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 705, in install_item
    dists = self.install_eggs(spec, download, tmpdir)
  File "/home/vagrant/.local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 855, in install_eggs
    return [self.install_wheel(dist_filename, tmpdir)]
  File "/home/vagrant/.local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 1073, in install_wheel
    os.path.dirname(destination)
  File "/usr/lib/python2.7/distutils/cmd.py", line 349, in execute
    util.execute(func, args, msg, dry_run=self.dry_run)
  File "/usr/lib/python2.7/distutils/util.py", line 309, in execute
    func(*args)
  File "/home/vagrant/.local/lib/python2.7/site-packages/setuptools/wheel.py", line 101, in install_as_egg
    self._install_as_egg(destination_eggdir, zf)
  File "/home/vagrant/.local/lib/python2.7/site-packages/setuptools/wheel.py", line 109, in _install_as_egg
    self._convert_metadata(zf, destination_eggdir, dist_info, egg_info)
  File "/home/vagrant/.local/lib/python2.7/site-packages/setuptools/wheel.py", line 157, in _convert_metadata
    os.path.join(egg_info, 'PKG-INFO'),
OSError: [Errno 2] No such file or directory

因此事实证明,此问题是由Vagrant / Virtualbox同步文件夹中的延迟引起的。 我试图在Vagrant VM中构建Python项目,该VM使用同步文件夹与主机文件系统共享。 将项目从同步文件夹中复制到VM中的另一个文件夹中,即可进行构建。 另一个有效的方法是在第157行的setup.tools/wheel.py源文件中添加time.sleep(1),然后再引发引起OS异常的os.rename。 这使文件系统有机会进行同步,因此可以解决此问题。

暂无
暂无

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

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