我在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,有何不可?我必须在安装文件中指定它吗?
发布于 2019-02-21 01:50:45
如果你想尝试一下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。
https://stackoverflow.com/questions/54792050
复制相似问题