tox 命令在 Windows 中引发异常

问题描述

ITNOA

我在 Windows 中有如下所示的 tox.ini

[testenv:bootstrap]
deps =
    jinja2
    matrix
    tox
skip_install = true
commands =
    python ci/bootstrap.py --no-env
passenv =
    *
; a generative tox configuration,see: https://tox.readthedocs.io/en/latest/config.html#generative-envlist

[tox]
envlist =
    clean,check,docs,py38,report
ignore_basepython_conflict = true

[testenv]
setenv =
    PYTHONPATH={toxinidir}/tests
    PYTHONUNBUFFERED=yes
passenv =
    *
usedevelop = false
deps =
    pytest
    pytest-travis-fold
    pytest-cov
commands =
    {posargs:pytest --cov --cov-report=term-missing -vv tests}

[testenv:check]
deps =
    docutils
    check-manifest
    flake8
    readme-renderer
    pygments
    isort
skip_install = true
commands =
    python setup.py check --strict --metadata --restructuredtext
    check-manifest {toxinidir}
    flake8
    isort --verbose --check-only --diff --filter-files .

[testenv:docs]
usedevelop = true
deps =
    -r{toxinidir}/docs/requirements.txt
commands =
    sphinx-build {posargs:-E} -b doctest docs dist/docs
    sphinx-build {posargs:-E} -b html docs dist/docs
    sphinx-build -b linkcheck docs dist/docs

[testenv:report]
deps =
    coverage
skip_install = true
commands =
    coverage report
    coverage html

[testenv:clean]
commands = coverage erase
skip_install = true
deps =
    coverage

当我运行 tox -e check 时,我看到以下异常和回溯

    PS D:\Projects\ControlProject\ControlProject> tox -e check
check create: D:\Projects\ControlProject\ControlProject\.tox\check
check installdeps: docutils,check-manifest,flake8,readme-renderer,pygments,isort
_______________________________________________________________________________________________________________________________________ summary _______________________________________________________________________________________________________________________________________
  check: commands succeeded
  congratulations :)
Traceback (most recent call last):
  File "C:\Users\ssoroosh\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\py\_error.py",line 66,in checked_call
    return func(*args,**kwargs)
OSError: [Errno 22] Invalid argument: 'C:\\Users\\ssoroosh\\AppData\\Local\\Microsoft\\WindowsApps\\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\\python.exe'

During handling of the above exception,another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\runpy.py",line 194,in _run_module_as_main
    return _run_code(code,main_globals,None,File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\runpy.py",line 87,in _run_code
    exec(code,run_globals)
  File "C:\Users\ssoroosh\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\Scripts\tox.exe\__main__.py",line 7,in <module>
  File "C:\Users\ssoroosh\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\tox\session\__init__.py",line 44,in cmdline
    main(args)
  File "C:\Users\ssoroosh\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\tox\session\__init__.py",line 69,in main
    exit_code = session.runcommand()
  File "C:\Users\ssoroosh\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\tox\session\__init__.py",line 197,in runcommand
    return self.subcommand_test()
  File "C:\Users\ssoroosh\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\tox\session\__init__.py",line 225,in subcommand_test
    run_sequential(self.config,self.venv_dict)
  File "C:\Users\ssoroosh\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\tox\session\commands\run\sequential.py",line 11,in run_sequential
    venv.finishvenv()
  File "C:\Users\ssoroosh\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\tox\venv.py",line 661,in finishvenv
    self.finish()
  File "C:\Users\ssoroosh\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\tox\venv.py",line 318,in finish
    live_config = self._getliveconfig()
  File "C:\Users\ssoroosh\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\tox\venv.py",line 289,in _getliveconfig
    base_resolved_python_sha256 = getdigest(base_resolved_python_path)
  File "C:\Users\ssoroosh\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\tox\venv.py",line 669,in getdigest
    return path.computehash("sha256")
  File "C:\Users\ssoroosh\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\py\_path\local.py",line 240,in computehash
    f = self.open('rb')
  File "C:\Users\ssoroosh\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\py\_path\local.py",line 369,in open
    return py.error.checked_call(open,self.strpath,mode)
  File "C:\Users\ssoroosh\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\py\_error.py",line 86,in checked_call
    raise cls("%s%r" % (func.__name__,args))
py.error.ENOTDIR: [Not a directory]: open('C:\\Users\\ssoroosh\\AppData\\Local\\Microsoft\\WindowsApps\\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\\python.exe','rb')

如何解决我的问题?

解决方法

我没有简单的解决方案,只有一个如何隔离问题以及如何自己解决的指南。

在您的 tox.ini 文件中发生了很多事情。尤其是在您的 check 环境中,您运行 4 个命令,此外它继承自通用 testenv

根据您的喜好更改顺序,但我会先...

  • 注释掉通用的 testenv,因为它似乎不是 check 环境工作所必需的,因此您可以避免副作用,例如可能引起的副作用来自passenv = *
  • 注释掉 check 环境中的最后三个命令,只运行第一个,然后添加第二个,依此类推,直到找到有问题的命令

错误消息表明其中一个命令需要一个目录,但已将路径传递给 python 解释器。

通过查看您的 tox.ini,我无法立即看出问题出在哪里,因此有关如何调试问题的说明,请参见上文。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...