tox在Windows上安装pyYaml失败

4

我的 tox.ini 文件在 Windows 上看起来像这样

[tox]
envlist = cpy27,dpy27
skip_missing_interpreters = True

[testenv]

basepython =
    cpy27: C:\Python27\python.exe
    dpy27: D:\Python27\python.exe

deps =
    pytest  

commands = py.test tests

但是,当我在命令提示符中执行“tox”时,出现了这个错误。为什么会这样?如果我在命令行上运行python setup.py install,我就看不到任何错误。

Installing collected packages: coverage, pytest-cov, requests, psutil, pytz, enum, argh, pathtools, PyYAML, watchdog, monit
  Running setup.py install for PyYAML: started
    Running setup.py install for PyYAML: finished with status 'error'
    Complete output from command d:\repos\foo\.tox\dpy27\scripts\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\foo\\appdata\\local\\temp\\pip-build-bbx8kz\\PyYAML\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\vikone\appdata\local\temp\pip-zyvbbh-record\install-record.txt --single-version-externally-managed --compile --install-headers d:\repos\foo\.tox\dpy27\include\site\python2.7\PyYAML:
    running install
    running build
    running build_py
    creating build
    creating build\lib.win-amd64-2.7
    creating build\lib.win-amd64-2.7\yaml
    copying lib\yaml\composer.py -> build\lib.win-amd64-2.7\yaml
    copying lib\yaml\constructor.py -> build\lib.win-amd64-2.7\yaml
    copying lib\yaml\cyaml.py -> build\lib.win-amd64-2.7\yaml
    copying lib\yaml\dumper.py -> build\lib.win-amd64-2.7\yaml
    copying lib\yaml\emitter.py -> build\lib.win-amd64-2.7\yaml
    copying lib\yaml\error.py -> build\lib.win-amd64-2.7\yaml
    copying lib\yaml\events.py -> build\lib.win-amd64-2.7\yaml
    copying lib\yaml\loader.py -> build\lib.win-amd64-2.7\yaml
    copying lib\yaml\nodes.py -> build\lib.win-amd64-2.7\yaml
    copying lib\yaml\parser.py -> build\lib.win-amd64-2.7\yaml
    copying lib\yaml\reader.py -> build\lib.win-amd64-2.7\yaml
    copying lib\yaml\representer.py -> build\lib.win-amd64-2.7\yaml
    copying lib\yaml\resolver.py -> build\lib.win-amd64-2.7\yaml
    copying lib\yaml\scanner.py -> build\lib.win-amd64-2.7\yaml
    copying lib\yaml\serializer.py -> build\lib.win-amd64-2.7\yaml
    copying lib\yaml\tokens.py -> build\lib.win-amd64-2.7\yaml
    copying lib\yaml\__init__.py -> build\lib.win-amd64-2.7\yaml
    running build_ext
    creating build\temp.win-amd64-2.7
    creating build\temp.win-amd64-2.7\Release
    checking if libyaml is compilable
    error: [Error 2] The system cannot find the file specified

更新

我注意到当我手动激活虚拟环境并执行 "pip install pyyaml" 时,会发生相同的错误。但是当我在常规命令提示符下执行相同的命令时,安装成功。

因此,这似乎是pyyaml和虚拟环境的问题,而不是tox本身的问题。另外,如果我在tox.ini中尝试使用easy_install命令,则可以正常工作,没有任何问题。

[testenv]
install_command = easy_install {opts} {packages}

tox.ini[testenv]下使用passenv = *会有什么变化吗? - The Compiler
1个回答

2
看起来这些二进制文件似乎没有适用于PyYAML,因此当PIP下载PyYAML时,它尝试构建它但失败了。我通过下载源代码、构建wheel并将其上传到本地的devpi服务器来解决我的计算机上的这个问题。然后我就可以在虚拟环境中使用pip安装它了。如果有影响的话,我使用的是Windows 10。 编辑:找到了问题所在。需要安装VC for Python(这是2.7版本,但请根据实际情况选择)。https://www.microsoft.com/en-gb/download/details.aspx?id=44266

1
为什么它在常规环境下可以工作,但在虚拟环境下却不能?按理说,在这种情况下两者都应该失败。 - user330612
我不知道。这不是我的代码。我只是想让它工作,现在它可以了。PyYaml似乎是一个几乎没有维护的项目,所以它可能不会得到修复。 - Matt_JD
1
嗨,我进一步查看了一下,并确定setuptools是问题所在。Setuptools 24.0.x无法安装pyyaml,而23.2.1可以正常工作。24.0.1和24.0.2失败并显示您上面提到的消息。24.0.0则会出现有关缺少文件的堆栈跟踪。我将继续深入研究。 - Matt_JD
找到了问题。需要安装VC for Python(这是2.7版本,但请使用适当的版本)。https://www.microsoft.com/en-gb/download/details.aspx?id=44266 - Matt_JD

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接