我正在尝试创建一个从
server.py
脚本运行的 python 应用程序的 .exe。我在单目录模式中使用
Auto-py-to-exe
,这给了我以下命令:
pyinstaller --noconfirm --onedir --console --icon "path" --name "name" --add-data "path" --add-data "path" --add-data "path" --hidden-import "openpyxl.cell._writer " --exclude-module "gevent server.py" "C:/Users/140476/Documents/57956_EXE_ANALISIS_DATO_TALADRADO/server.py"
这些是我的版本:
6067924 INFO: PyInstaller: 6.0.0
6067938 INFO: Python: 3.9.13 (conda)
6067956 INFO: Platform: Windows-10-10.0.19045-SP0
Running auto-py-to-exe v2.40.0
我收到以下错误:
6258721 INFO: Loading module hook 'hook-gevent.py' from
File "C:\ProgramData\Anaconda3\lib\site-packages\packaging\markers.py", line 215, in _get_env
raise UndefinedEnvironmentName(
packaging.markers.UndefinedEnvironmentName: 'extra' does not exist in evaluation environment.
Project output will not be moved to output folder
Complete.
以前,我可以在我的 python 项目中生成 .exe。现在我添加了
pysimplegui
一个使用 Multiprocessing
库的文件浏览器。因此,这让我认为失败可能与这个库有关。当我从控制台运行它时,它工作得很好。
附件是我的代码的一些部分:
if __name__ == '__main__':
if sys.platform.startswith('win'):
# On Windows calling this function is necessary.
freeze_support()
def interact_callbacks(self):
@callback(
Output('add-automatically-button', 'children'),
Input('add-automatically-button', 'n_clicks')
)
def update_output(n_clicks):
freeze_support()
if n_clicks is not None:
print('before process')
p = Process(target=startInteraction)
p.start()
return 'Clicked!'
else:
return 'Add automatically'
欢迎任何形式的帮助,因为我不知道如何处理这个问题。提前非常感谢您。
我在 Linux 上使用 PyInstaller 时遇到了相同的错误消息,但我可以想象您的情况的原因也可能是使用虚拟 Anaconda 环境。 最终为我解决问题的是在虚拟环境中通过
conda
而不是 pip
安装 PyInstaller (正如类似案例中提到的 here )。
由于 Auto-py-to-exe 是基于 PyInstaller 构建的,因此尝试一下也可能有所帮助
conda install PyInstaller
或者,如果存在,Auto-py-to-exe 的 conda 包。不过,这只是一个猜测,我还没有在 Windows 上尝试过。