繁体   English   中英

执行使用Py2exe创建的可执行文件时导入NumPy时出错

[英]Error importing NumPy when executing an executable created with Py2exe

我在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 Files\Continuum\Anaconda3\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Program Files\Continuum\Anaconda3\tcl\tk8.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。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM