微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

来自 py2exe 的可执行文件停止运行

如何解决来自 py2exe 的可执行文件停止运行

我正在尝试使用 py2exe 从 Python 脚本创建 .exe。经过一些令人厌烦的研究,我能够运行一个功能性的 .exe。但是,我不得不在我的 .py 中添加更多行,包括一个新的导入。

我的旧进口是:

import numpy as np
import pandas as pd
import os
from scipy import signal
import pywt

我的旧 setup.py 是:

from setuptools import setup
from distutils.core import setup
import py2exe

excludes = []
includes = ["scipy.signal","scipy._lib.messagestream","scipy.spatial.transform._rotation_groups","scipy.special.cython_special","pywt._extensions._cwt"]

opts = {
    "py2exe": {
        "includes":includes,"excludes":excludes
    }
}

setup(console=['Shweep.py'],options=opts)

我刚刚添加了我可以从其他相关问题中找到的任何包含,最终它起作用了。

我的问题是新脚本。我有一些新的导入:

import numpy as np
import pandas as pd
import os
from scipy import signal
from scipy.interpolate import interp1d
import pywt
import math

并且我的 setup.py 运行,带有关于缺少模块的警告(第一次也有这些,虽然我不确定它们是否相同)。但是,当我尝试使用 cmd 运行 .exe 时,该程序在几秒钟后停止运行,显示即时调试消息,告诉我使用 Visual Studio 进行调试。当我尝试使用 Visual Studio 在不同的 PC 上运行相同的 .exe 时,该消息甚至不显示

对不起,如果这很简单,我是 py2exe 的初学者

编辑:我试图隔离部分代码以找出导致错误的原因。 好像和这两个函数有关:

def filter_oximetry(x,t):
    """
    
    Filters a pulse oximetry signal for usage in the find_oximetry_events() function. 
    
    The signal is filtered through a 500th order FIR linear phase lowpass filter with a
    0,1 Hz cutoff frequency. All the values greater than the mean + 9 are replaced by 
    mean - 20 and those bellow mean - 9 are replaced with mean + 20 

    Parameters
    ----------
    x : List or numpy array.
        Oximetry signal.
    t : List or numpy array.
        Signal time.

    Returns
    -------
    y : List or numpy array.
        Filtered signal values.

    """
    
    # Calculating the sampling frequency
    fs = 1/(t[1] - t[0])
    
    # Lowpass linear phase FIR filter,designed through REMEZ.
    # 1500th order,with 0.1 Hz cutoff frequency and passband 
    # gain of 1.
    coef = signal.remez(numtaps = 500,bands = [0,0.1,0.2,fs/2],desired = [1,0],Hz = fs,type = "bandpass")
    
    # Steady state initial conditions    
    zi = signal.lfilter_zi(coef,1) 
    
    # Filtering the signal
    y,_ = signal.lfilter(coef,1,x,zi = zi)
    
    # Compensating for a gain lower than 1 in the passband
    y += 6
    
    #Getting rid of spikes
    mean = y.mean()
    for n in range(1,len(y) - 1):
      if (y[n] >= mean + 9) or (y[n] <= mean - 9):
          
        # Interpolation
        y[n] = y[n - 1] - (y[n - 1] - y[n + 1] / 2) 
        
        # If it is still outside the limits...
        if (y[n] >= mean + 9): 
          y[n] = mean - 20
        
        # If it is still outside the limits...
        if (y[n] <= mean - 9): 
          y[n] = mean + 20
    
    return y

def filter_flow(x,flow_t):
    """
    
    Filters an oronasal thermistor signal for usage in the find_flow_events() function. 
    
    The signal is filtered through a 249th order FIR linear phase lowpass filter with a
    1 Hz cutoff frequency.

    Parameters
    ----------
    x : List or numpy array.
        Oximetry signal.
    flow_t : List or numpy array.
        Signal time.

    Returns
    -------
    flow_y : List or numpy array.
        Filtered signal values.

    """

    # Calculating the sampling frequency
    fs = 1/(flow_t[1] - flow_t[0])
    
    # Lowpass linear phase FIR filter,with 0.9 Hz cutoff frequency and passband 
    # gain of 1.
    coef = signal.remez(249,[0,1.5,[1,type = "bandpass")


    # Steady state initial conditions
    zi = signal.lfilter_zi(coef,1) 
    
    # Filtering the signal
    flow_y,zi = zi) 
    
    return flow_y

我仍然不知道为什么它不输出任何错误消息。此外,如果我使用 spyder,它运行良好,但在使用可执行文件时则不然

解决方法

要了解您的问题是什么,您可以查看此帖子:

Here

您的解决方案:

我测试了你的脚本,我修改了你的 setup.py,当我排除几个模块时它是 fonctionnal :

from setuptools import setup
from distutils.core import setup
import py2exe

setup(options = {
    "py2exe":
        {   
            "excludes": ["_pytest","qtpy"],}
    },console=['Shweep.py'])

我排除了这个模块,因为它们会产生一些问题。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。