执行使用PY2EXE创建的可执行文件时导入Numpy的错误



我在Windows上使用PY2EXE实现了我的第一个可执行文件。脚本使用库:

import os
import pandas as pd
import numpy as np
from pandas import ExcelWriter
import datetime as dt

我的设置文件是:

from cx_Freeze import setup, Executable
import os
import sys
os.environ['TCL_LIBRARY'] = r'C:Program FilesContinuumAnaconda3tcltcl8.6'
os.environ['TK_LIBRARY'] = r'C:Program FilesContinuumAnaconda3tcltk8.6'
base = None
if sys.platform == "win32":
    base = "Win32GUI"
setup(name = "my first executable",
    version = "0.1",
    description = "Executable",
    executables = [Executable("myscript.py")])

我试图测试我的。通过从终端启动命令来exe:

>> myscript.exe

但是返回错误:

Importerror:缺少所需的依赖关系['numpy']。

如何解决此错误?我安装了numpy,为什么不呢?我必须在设置文件中指定它吗?

如果您想尝试一下Pyinstaller,我会使用此小脚本使我的生活更轻松:

import sys, os
import tkinter as tk
from tkinter import filedialog
print(
    """
=======================================
Create a .exe file from a Python Script
=======================================
Select the Python script you want to create the .exe from:
""")
root = tk.Tk()
root.withdraw()
file_p = filedialog.askopenfilename(initialdir = "./", title = "Select file", filetypes = ((".py files","*.py"), (".pyw files","*.pyw"))) 
if file_p == "." or file_p == None:
    sys.exit()
if file_p.endswith('.pyw'):
    cmd = ('pyinstaller.exe --windowed --onefile ' + '"' + file_p + '"')
    os.system(cmd)
if file_p.endswith('.py'):
    cmd = ('pyinstaller.exe --onefile ' + '"' + file_p + '"')
    os.system(cmd)
os.system('pause')

它在脚本旁边旁边的DIST文件夹中创建一个.exe。

最新更新