我有一个简单的Python代码(3.12版本)。它只计算用户输入的名称的ASCII的总和:
import sys
args = sys.argv
name=args[1]
print(f"Hello, {name}!")
print("Here is some intelligence that will return a number you will NEVER understand how it is
computed :-D \n")
name = name.lower()
ascii_sum = 0
for char in name:
if char.isalpha():
ascii_value = ord(char)
ascii_sum += ascii_value
print(ascii_sum)
我在一个名为
dummy_fct.exe
。因为出于某种原因,我需要能够从ipynb笔记本调用(Python)可执行文件。
现在,我正尝试从新笔记本调用此可执行文件:
import subprocess
import sys
name = input("Quel est ton nom ? ")
subprocess.run(["dummy_fct.exe", name], capture_output=True, text=True)
但出现以下错误:
CompletedProcess(args=[dummy_fct.exe','PDH'],returncode=1,stdout='',stderr='[4004]pyymod02_importers的模块对象为NULL!\n回调(最后一次调用):\n File“PyInstaller\loader\pymod02_importers.py”,第22行,在\n File“pathlib.py”第14行,在文件“urllib\parse.py”第40行,in\nModuleNotFoundError:没有名为“ipaddress”的模块\n回调(最后一次调用):\n文件“PyInstaller\loader\pyboot01_bootstrap.py”,第17行,in \nModuleNNotFoundError:无名为“pyimod02_importers”的模块\n[4004]由于未处理的异常,无法执行脚本“pyiboot01_boot strap”!\n')
我确实说我根本不理解这个错误信息。。。你能帮我吗?
EDIT:可执行文件是通过以下两个命令创建的:
jupyter nbconvert --to script dummy_fct.ipynb
pyinstaller --onefile dummy_fct.py