【问题标题】:ImportError (missing dependencies ['numpy']) at the time of executing the .exe执行 .exe 时的 ImportError(缺少依赖项 ['numpy'])
【发布时间】:2019-02-23 21:51:14
【问题描述】:

我编写了一个 Python 小程序,以便使用 Pandas、gzip 和 shutil 库从几个压缩的 gzip 文件中提取数据(.csv 文件)。提取 .csv 文件后,它们将合并为一个大的 .csv 唯一文件。

我的程序支持 Python 版本 2.73.7

在构建一个 .exe 以更轻松地使用这个小程序并与没有安装 Python 的计算机兼容时,我犯了错误,因为它不起作用。

这是我从 PyInstaller 执行 .exe 的主文件夹:

注意:“00000(0)”文件是没有扩展名的.gzip,里面只有一个.csv文件,也没有扩展名。

你有办法解决这个问题吗?

这是我在实际执行时从终端得到的:

创建.exe的终端命令:

pyinstaller.exe --clean --onefile Convierte_Rar_En_Csv_Final.py --name Transforma2 --hidden-import numpy

版本:

  • Python:2.7.15
  • pyinstaller: 3.4(为了安装这个库,我刚刚从here 下载了文件夹,然后将其移动到C:\YourPythonEnviroment\Lib\site-packages\PyInstaller-3.4,最后在我进入文件夹 PyInstaller-3.4 python setup.py install 后从终端制作。)李>
  • 熊猫:0.24.0
  • numpy:1.16.0
  • pytz: 2018.9
  • wxPython 4.0.4
  • 设置工具:40.8.0
  • python-dateutil: 2.8.0

我的程序代码:

def DescomprimeYUne(path):
    import pandas as pd
    import gzip , shutil
    import numpy

    results = pd.DataFrame([])

    for filename in os.listdir(path):
        pathFile = path + filename
        if filename != __file__.split("/")[-1] and not os.path.isdir(pathFile):
            # # Descomprimo fichero
            with gzip.open(pathFile, 'rb') as f_in:
                with open(pathFile + '.csv', 'wb') as f_out:
                    shutil.copyfileobj(f_in, f_out)

            # Borro fichero original
            os.remove(pathFile)

            # Concateno a CSV final
            namedf = pd.read_csv(pathFile + ".csv", skiprows=0)
            results = results.append(namedf)

           # Borro fichero csv
           os.remove(pathFile + '.csv')

    results.to_csv(path + "final.csv")
if __name__ == "__main__":
DescomprimeYUne("./")

我也关注了this tutorial,但它对我不起作用。

【问题讨论】:

    标签: python pandas numpy pyinstaller


    【解决方案1】:

    不久前,我也将我的 python 应用程序作为可执行文件分发。在运行时我还遇到了几个导入错误或丢失文件错误,但根据我的经验,模块 cx_freeze 似乎非常擅长正确处理。

    Cx_freeze 可以在任何 python 工作的操作系统上运行,并支持 2.7+ 或 3+。 我强烈建议您观看本教程,它对我有很大帮助。 https://www.youtube.com/watch?v=HosXxXE24hA

    以下是设置脚本的示例:

    import cx_Freeze 
    from cx_Freeze import *
    import sys 
    import os
    
    
    base = None
    
    if sys.platform =='win32':
        base = "Win32GUI"
    
    executables = [cx_Freeze.Executable("DescomprimeYUne.py", base=base)]
    
    # Stating what modules and files our app needs so they can be included in the build
    cx_Freeze.setup(
        name = "DescomprimeYUne", # Name of exe
        options = {"build_exe":{"packages":["numpy", "pandas", "gzip", "shutil"], # Include packages used here
                              "include_files":["filename"]}}, # optional you can include any files your script needs here
        version = "0.01",
        description="DescomprimeYUne",
        executables = executables
        )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-29
      • 1970-01-01
      • 2020-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-01
      • 1970-01-01
      相关资源
      最近更新 更多