Error importing NumPy when executing an executable created with Py2exe

余生颓废 提交于 2019-12-08 10:44:11

问题


I realized my first executable with Py2exe on Windows. The script uses libraries:

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

My setup file is:

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")])

I tried to test my. exe by launching the command from the terminal:

>> myscript.exe

But the error is returned:

ImportError: Missing required dependencies [' NumPy '].

How can I fix this error? I installed NumPy, why not? Do I have to specify it in the setup file?


回答1:


If you want to give PyInstaller a try, I use this little script to make my life easier:

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')

It creates a single .exe in a dist folder located next to wherever the script is.



来源:https://stackoverflow.com/questions/54792050/error-importing-numpy-when-executing-an-executable-created-with-py2exe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!