subprocess.run() 在 pycharm python 中不起作用

问题描述 投票:0回答:0

我在 python 中通过 PyCharm 运行以下代码:

#! /usr/bin/env python3
import fileinput
import itertools
import os
import sys
from subprocess import DEVNULL, run

implementations = [
                   ('ref', ['shake', 'sha2', 'haraka']),
                   ('haraka-aesni', ['haraka']),
                   ('shake-avx2', ['shake']),
                   ('sha2-avx2', ['sha2']),
                   ]

options = ["f", "s"]
sizes = [128, 192, 256]
thashes = ['robust', 'simple']

for impl, fns in implementations:
    params = os.path.join(impl, "params.h")
    for fn in fns:
        for opt, size, thash in itertools.product(options, sizes, thashes):
            paramset = "sphincs-{}-{}{}".format(fn, size, opt)
            paramfile = "params-{}.h".format(paramset)

            print("Benchmarking", paramset, thash, "using", impl, flush=True)

            params = 'PARAMS={}'.format(paramset)  # overrides Makefile var
            thash = 'THASH={}'.format(thash)  # overrides Makefile var

            run(["make", "-C", impl, "clean", thash, params],
                stdout=DEVNULL, stderr=sys.stderr)
            run(["make", "-C", impl, "benchmarks", thash, params],
                stdout=DEVNULL, stderr=sys.stderr)
            run(["make", "-C", impl, "benchmark", thash, params],
                stdout=sys.stdout, stderr=sys.stderr)

            print(flush=True)


从 github 克隆这段代码,代码必须工作。

我尝试运行代码,但收到以下错误消息:

C:\Users\pc\anaconda3\python.exe C:/Users/pc/PycharmProjects/sphincsplus/benchmark.py
Traceback (most recent call last):
  File "C:/Users/pc/PycharmProjects/sphincsplus/benchmark.py", line 31, in <module>
    run(["make", "-C", impl, "clean", thash, params],
  File "C:\Users\pc\anaconda3\lib\subprocess.py", line 493, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Users\pc\anaconda3\lib\subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\pc\anaconda3\lib\subprocess.py", line 1311, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
Benchmarking sphincs-shake-128f robust using ref

我注意到它会以某种方式进入 anaconda3 路径,但为什么呢?我不需要此代码的 anadoca。我认为这是问题所在,但我不确定也无法理解如何解决它。

更新:

我按照@tripleee 提到的说明进行操作,我下载了 MinGW,并为其添加了 PATH,仍然出现错误,但不同的是:

Benchmarking sphincs-sha2-256s simple using sha2-avx2
process_begin: CreateProcess(NULL, /usr/bin/gcc -Wall -Wextra -Wpedantic -Wmissing-prototypes -O3 -std=c99 -march=native -flto -fomit-frame-pointer -DPARAMS=sphincs-sha2-256s -o test/benchmark hash_sha2.c hash_sha2x8.c thash_sha2_simple.c thash_sha2_simplex8.c sha2.c sha256x8.c sha512x4.c sha256avx.c address.c randombytes.c merkle.c wots.c utils.c utilsx8.c fors.c sign.c test/benchmark.c, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [test/benchmark] Error 2
process_begin: CreateProcess(NULL, /usr/bin/gcc -Wall -Wextra -Wpedantic -Wmissing-prototypes -O3 -std=c99 -march=native -flto -fomit-frame-pointer -DPARAMS=sphincs-sha2-256s -o test/benchmark hash_sha2.c hash_sha2x8.c thash_sha2_simple.c thash_sha2_simplex8.c sha2.c sha256x8.c sha512x4.c sha256avx.c address.c randombytes.c merkle.c wots.c utils.c utilsx8.c fors.c sign.c test/benchmark.c, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [test/benchmark] Error 2
make: Entering directory 'C:/Users/pc/PycharmProjects/sphincsplus/sha2-avx2'
/usr/bin/gcc -Wall -Wextra -Wpedantic -Wmissing-prototypes -O3 -std=c99 -march=native -flto -fomit-frame-pointer -DPARAMS=sphincs-sha2-256s  -o test/benchmark hash_sha2.c hash_sha2x8.c thash_sha2_simple.c thash_sha2_simplex8.c sha2.c sha256x8.c sha512x4.c sha256avx.c address.c randombytes.c merkle.c wots.c utils.c utilsx8.c fors.c sign.c test/benchmark.c 
Makefile:38: recipe for target 'test/benchmark' failed
make: Leaving directory 'C:/Users/pc/PycharmProjects/sphincsplus/sha2-avx2'


Process finished with exit code 0
python anaconda subprocess
© www.soinside.com 2019 - 2024. All rights reserved.