Pyinstaller 可执行文件找不到包含的“flask-compress”发行版

2024-01-12

这是我的系统信息:

123 INFO: PyInstaller: 4.0
123 INFO: Python: 3.5.4
124 INFO: Platform: Windows-10-10.0.18362-SP0

我一直在尝试使用 Pyinstaller 生成一个 Python (PyQt) 可执行文件以在应用程序中使用。但是,当我打包可执行文件并运行它时,它会抛出以下错误:

pkg_resources.DistributionNotFound: The 'flask-compress' distribution was not found and is required 
by the application
[14684] Failed to execute script main

这种依赖关系已经存在于我的虚拟环境中,我尝试指定站点包目录的路径和 Flask_compress 导入,如下所示:

pyinstaller --paths C:\Users\alan9\PycharmProjects\PracticumProject\venv\Lib\site-packages --hidden-import=flask_compress main.py

注意:我尝试使用不同的 python 版本、不同的 pyinstaller 标志(onefile、windowed、onedir)、在运行 Windows 7/10 的不同计算机上、在 Windows 10 VM 的干净副本上以及使用fbs 但我总是收到相同的错误消息:(


我用猴子补丁解决了这个问题。只需将此代码粘贴到您在 dash 之前导入的模块中即可。就我而言,我有flask-compress==1.5.0,所以我只是对版本进行了硬编码,但你可能可以做一些更聪明的事情。

"""
Simple module that monkey patches pkg_resources.get_distribution used by dash
to determine the version of Flask-Compress which is not available with a
flask_compress.__version__ attribute. Known to work with dash==1.16.3 and
PyInstaller==3.6.
"""

import sys
from collections import namedtuple

import pkg_resources

IS_FROZEN = hasattr(sys, '_MEIPASS')

# backup true function
_true_get_distribution = pkg_resources.get_distribution
# create small placeholder for the dash call
# _flask_compress_version = parse_version(get_distribution("flask-compress").version)
_Dist = namedtuple('_Dist', ['version'])

def _get_distribution(dist):
    if IS_FROZEN and dist == 'flask-compress':
        return _Dist('1.5.0')
    else:
        return _true_get_distribution(dist)

# monkey patch the function so it can work once frozen and pkg_resources is of
# no help
pkg_resources.get_distribution = _get_distribution
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Pyinstaller 可执行文件找不到包含的“flask-compress”发行版 的相关文章

随机推荐