简体   繁体   English

运行 python 脚本作为 exe

[英]running python script as exe

I wrote a basic script in python 3.7 that does what I need.我在 python 3.7 中编写了一个基本脚本,它可以满足我的需要。 However it needs to run on another person's computer.但是它需要在另一个人的计算机上运行。 I want to run this as an exe then just change the icon logo.我想将其作为 exe 运行,然后只需更改图标徽标。

I have installed py2exe (I believe).我已经安装了 py2exe(我相信)。 Below is the python script:下面是 python 脚本:

pip install py2exe
import os
os.startfile(r"\\ComputerName\c$\users\UserName\desktop\Lullaby wav.wav")

I have another file, that looks like this (basing this off this thread Can I somehow "compile" a python script to work on PC without Python installed? ):我有另一个文件,看起来像这样(基于此线程我可以以某种方式“编译”一个 python 脚本以在没有安装 Python 的 PC 上工作吗? ):

import sys
from distutils.core import setup
import py2exe

entry_point = sys.argv[1]
sys.argv.pop()
sys.argv.append('py2exe')
sys.argv.append('-q')

opts = {
    'py2exe': {
        'compressed': 1,
        'optimize': 2,
        'bundle_files': 1
    }
}

setup(console=[entry_point], options=opts, zipfile=None)

I then open up cmd and try to use the compile.py file on myscript per the instructions but get an erro:然后我打开 cmd 并尝试按照说明使用 myscript 上的 compile.py 文件,但出现错误:

File "", line 1 python compile.py covid.pyw ^文件“”,第 1 行 python compile.py covid.pyw ^

You can use PyInstaller.您可以使用 PyInstaller。 Which is inbuilt, if not you can install it.这是内置的,如果没有,您可以安装它。 Just very simple lines in cmd to create an exe file and also you can add icon using -i (I think so).在 cmd 中只需非常简单的行来创建一个 exe 文件,您也可以使用-i添加图标(我认为是这样)。

Visit this to learn about it from realpython which I love to read about python tutorials: https://realpython.com/pyinstaller-python/访问这里以从我喜欢阅读有关 python 教程的 realpython 了解它: https://realpython.com/pyinstaller-python/

By the way you can use python 3.8.6 or 3.9 which is the updated version of python 3.7.顺便说一句,您可以使用 python 3.8.6 或 3.9,这是 python 3.7 的更新版本。

Make sure your device is up to date, that could be the problem, also pyinstaller is a better, more modern alternative确保您的设备是最新的,这可能是问题所在,pyinstaller 也是一个更好、更现代的替代品

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

相关问题 从Java运行带有参数的exe python脚本 - Running python script, as exe, with parameters, from Java pyinstaller python exe 未运行 [脚本中未处理的异常] - pyinstaller python exe not running [unhandled exception in script] Python脚本,pyodbc代码没有使用由py2exe制作的EXE运行 - Python script with pyodbc code not running using EXE made from py2exe 将Python脚本编译为exe - Compiling Python script to exe python 3.5上的exe的Python脚本 - Python script to exe on python 3.5 当 python.exe 设置为“以管理员身份运行”时,在 Windows 中运行 python 脚本会给出“无法使用...创建进程” - Running a python script in Windows gives "Unable to Create Process Using ..." when python.exe set to 'run as administrator' 从 VBA 运行 Python 脚本没有任何反应,但是当我从 python.exe 运行它时,它起作用了 - Running Python script from VBA nothing happens, but when I run it from python.exe, it works Python 2.7:如何在运行python gui .exe脚本时摆脱cmd窗口 - Python 2.7 : How to get rid of cmd window while running a python gui .exe script Python 从 C# 运行的脚本离开 Python 在后台运行的 exe 吃 ZCD69B495761980DE - Python Script run from C# leaves Python exe running in background eating memory 从python运行外部EXE - Running external EXE from python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM