PyInstaller可执行文件找不到包含的flASK-COMPRESS [英] Pyinstaller executable cannot find 'flask-compress' distribution that is included

查看:25
本文介绍了PyInstaller可执行文件找不到包含的flASK-COMPRESS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的系统信息:

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:Usersalan9PycharmProjectsPracticumProjectvenvLibsite-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

这篇关于PyInstaller可执行文件找不到包含的flASK-COMPRESS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆