python 虚拟环境调用allure报错:FileNotFoundError: [WinError 2] 系统找不到指定的文件

一、遇到的问题

python代码调用命令行 allure命令报错,提示找不到allure这个命令。python虚拟环境中已经安装了pytest-allure

代码如下:

python 复制代码
import subprocess

if __name__ == "__main__":
    # retcode = pytest.main()

    subprocess.call(['pytest', '--alluredir=./report/allure'])
    subprocess.call(['allure', 'serve', './report/allure'])

报错如下:

python 复制代码
Traceback (most recent call last):
  File "D:\project\python\pytestDemo\main.py", line 17, in <module>
    subprocess.call(['allure', 'serve', './report/allure'])
  File "C:\Users\liyuanhong\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 389, in call
    with Popen(*popenargs, **kwargs) as p:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\liyuanhong\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\liyuanhong\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 1538, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [WinError 2] 系统找不到指定的文件。

查看了我的python虚拟环境: venv/Scripts 目录下确实没有 allure 命令

二、解决方法

下载 allure 命令行工具

下载地址:Central Repository: io/qameta/allure/allure-commandline

选择对应的版本下载,解压到项目目录如下:

创建一个 allure.bat的超链接,将超链接文件拷贝到 venv/Scripts 目录下

修改代码如下即可:

python 复制代码
import subprocess

if __name__ == "__main__":
    # retcode = pytest.main()

    subprocess.call(['pytest', '--alluredir=./report/allure'])
    subprocess.call(['allure.bat', 'serve', './report/allure'])
相关推荐
似水এ᭄往昔几秒前
【Linux】--文件系统之软硬链接
linux·运维·服务器
叶 落3 分钟前
Ubuntu 通过 Docker 安装 Mysql8
linux·ubuntu·docker
财经资讯数据_灵砚智能7 分钟前
基于全球经济类多源新闻的NLP情感分析与数据可视化(夜间-次晨)2026年5月2日
人工智能·python·信息可视化·自然语言处理·ai编程
skiy12 分钟前
SpringBoot项目中读取resource目录下的文件(六种方法)
spring boot·python·pycharm
乌萨奇也要立志学C++12 分钟前
【Linux】Socket编程UDP Echo 服务器→翻译服务器→多人聊天室
linux·服务器·udp
2601_9561394214 分钟前
集团品牌全案公司哪家专业
大数据·人工智能·python
ouliten14 分钟前
[Triton笔记1]核心概念
笔记·python·深度学习·triton
清水白石00815 分钟前
生成器不是性能银弹:什么时候该用 `yield` 省内存,什么时候它会拖慢 Python 数据处理吞吐?
开发语言·python·原型模式
李松桃16 分钟前
Python爬虫-实战
爬虫·python
代码中介商24 分钟前
Linux多线程编程进阶:fork与锁的交互及网络编程入门
linux·运维·服务器