问题描述
这是python脚本:
我使用 Visual Studio Code 通过以下命令运行文件:
我得到了想要的结果:
现在我尝试通过在我的脚本所在的文件夹中打开 PowerShell 来创建 .exe 文件 运行下一行:
这是我得到的东西(不包括 otherScripts 文件夹):
现在我打开 CMD,导航到所需的文件夹,然后使用下一行代码运行 .exe 文件:
这是我收到的第一个警告:
这是我得到的回溯(控制台立即关闭,我无法使用截图工具来捕获错误,所以我通过 C# Win Form 应用程序运行它并将标准错误重定向到表单中的标签) :
我试过了:
- pip install 转换器 -U。
- 使用命令 --onedir 代替 --onefile
- 脚本中的第 3 行(导入 tqdm)最近被添加以尝试修复错误。因为上面写着“tqdm 没有找到,是应用程序需要的。”,所以我就把它放在那里了。
- 将 pyinstaller 和转换器更新到最新版本。
- 其他我现在不记得的事情。
这些都没有奏效。我有点卡在这里。 如果您能帮助我解决此问题,我将不胜感激。
解决方法
尝试使用 --exclude-module=torch
构建?(取自:https://github.com/pyinstaller/pyinstaller/issues/4695)
对我来说,将“tqdm目录”添加到数据中解决了问题:)
在脚本.spec中:
import './App.css';
import React,{ useEffect,useState } from 'react';
function App() {
const time = 20;
const [count,setCount] = useState(time);
const [start,setStart] = useState(false)
useEffect(() => {
if (start) {
if (count > 0) {
setTimeout(() => setCount(count - 1),1000);
} else {
setCount('Times up');
}
}
},[count,start])
const startCount = () => {
setStart(true)
}
return (
<div className="App">
<div>{count}</div>
<button onClick={startCount}> start </button>
<button> pauze </button>
</div>
);
}
export default App;